1 Objective : CIFAR_10 Image Classification with R + Tensorflow_GPU

  • The main task is to build a feed-forward convolutional neural networks(CNNs) for images classification with the benchmark CIFAR_10 dataset, which can be downloaded from https://www.cs.toronto.edu/~kriz/cifar.html .

2 Software and Hardward Configuration :

  • R version 3.5.2 Patched (2019-01-14 r75992)
  • keras, tensorflow support for CPU
  • Platform: x86_64-w64-mingw32/x64 (64-bit)
  • Processor Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz, 1800 Mhz, 4 Core(s), 8 Logical Processor(s)
  • Physical Memory : 4GB
  • Graphic Display Card : GeFore MX150
  • backend: window platform under minconda + tensorflow_gpu envirnoment
  • backend: python 3.7 verion + Tensorflow_gpu in RStduio

3 load image file : dataset_cifar10()

  • dataset_cifar10 contains 50,000 32x32 color training images, labeled over 10 categories, and 10,000 test images
  • Lists of training and test data: train_x, train_y, test_x, test_y.
  • The x data is an array of RGB image data with shape (num_samples, 3, 32, 32).
  • The y data is an array of category labels (integers in range 0-9) with shape (num_samples).

5 Model Defining : keras_model_sequential (Tensorflow 1.0 GPU version in R)

## Model: "sequential"
## ___________________________________________________________________________
## Layer (type)                     Output Shape                  Param #     
## ===========================================================================
## conv2d (Conv2D)                  (None, 32, 32, 32)            896         
## ___________________________________________________________________________
## activation (Activation)          (None, 32, 32, 32)            0           
## ___________________________________________________________________________
## conv2d_1 (Conv2D)                (None, 30, 30, 32)            9248        
## ___________________________________________________________________________
## activation_1 (Activation)        (None, 30, 30, 32)            0           
## ___________________________________________________________________________
## max_pooling2d (MaxPooling2D)     (None, 15, 15, 32)            0           
## ___________________________________________________________________________
## dropout (Dropout)                (None, 15, 15, 32)            0           
## ___________________________________________________________________________
## conv2d_2 (Conv2D)                (None, 15, 15, 32)            9248        
## ___________________________________________________________________________
## activation_2 (Activation)        (None, 15, 15, 32)            0           
## ___________________________________________________________________________
## conv2d_3 (Conv2D)                (None, 13, 13, 32)            9248        
## ___________________________________________________________________________
## activation_3 (Activation)        (None, 13, 13, 32)            0           
## ___________________________________________________________________________
## max_pooling2d_1 (MaxPooling2D)   (None, 6, 6, 32)              0           
## ___________________________________________________________________________
## dropout_1 (Dropout)              (None, 6, 6, 32)              0           
## ___________________________________________________________________________
## flatten (Flatten)                (None, 1152)                  0           
## ___________________________________________________________________________
## dense (Dense)                    (None, 512)                   590336      
## ___________________________________________________________________________
## activation_4 (Activation)        (None, 512)                   0           
## ___________________________________________________________________________
## dropout_2 (Dropout)              (None, 512)                   0           
## ___________________________________________________________________________
## dense_1 (Dense)                  (None, 10)                    5130        
## ___________________________________________________________________________
## activation_5 (Activation)        (None, 10)                    0           
## ===========================================================================
## Total params: 624,106
## Trainable params: 624,106
## Non-trainable params: 0
## ___________________________________________________________________________
## Time difference of 30.82586 mins
CIFAR_10 Image Classification: Accuracy Plot

CIFAR_10 Image Classification: Accuracy Plot

8 Loadmymodel: Confusion Matrix

flyer car bird cat deer dog frog horse ship truck
flyer 84.1 1.4 9.6 2.2 2.6 1.5 0.8 1.5 5.3 3.3
car 2.7 92.3 0.3 1.1 0.2 0.0 0.2 0.3 3.2 10.4
bird 2.3 0.1 57.0 3.9 5.6 1.8 4.5 1.8 0.3 0.3
cat 2.1 0.4 9.6 66.7 10.7 18.2 9.3 5.4 2.1 2.0
deer 0.4 0.1 5.9 2.8 61.8 2.0 2.1 2.3 0.2 0.1
dog 0.2 0.0 7.6 14.7 4.3 70.8 2.0 7.0 0.1 0.1
frog 0.3 0.6 6.1 4.0 4.4 1.1 79.0 0.1 0.2 0.4
horse 1.5 0.1 3.1 2.3 9.3 4.2 1.1 80.9 0.3 1.4
ship 4.5 1.6 0.6 1.2 0.9 0.3 0.8 0.0 87.6 2.3
truck 1.9 3.4 0.2 1.1 0.2 0.1 0.2 0.7 0.7 79.7

9 References:

  • Krizhevsky, Hinton, and others (2009)
  • Hinton et al. (2012)

Hinton, Geoffrey E., Nitish Srivastava, Alex Krizhevsky, Ilya Sutskever, and Ruslan R. Salakhutdinov. 2012. “Improving Neural Networks by Preventing Co-Adaptation of Feature Detectors,” July. http://arxiv.org/abs/http://arxiv.org/abs/1207.0580v1.

Krizhevsky, Alex, Geoffrey Hinton, and others. 2009. “Learning Multiple Layers of Features from Tiny Images.” Citeseer.