1
votes

I am running the tutorial example cifar10_cnn.py from here.

Here is the environment/configuration for the test:

  • Windows 10
  • Keras 1.2.0
  • Theano 0.8.2
  • Numpy 1.11.2
  • Enthought/Canopy/MKL(2017.0.1-1)
  • .theanorc [blas] ldflags -L... -lmk2_rt

The program took about one and half day to finish 200 epochs. The following figure shows the header and the last three epochs.

Using Theano backend

X_train shape: (50000L, 32L, 32L, 3L) ...

Epoch 198/200 50000/50000 [==============================] - 639s - loss: 1.7894 - acc: 0.3497 - val_loss: 1.5930 - val_acc: 0.3968

Epoch 199/200 50000/50000 [==============================] - 617s - loss: 1.8111 - acc: 0.3446 - val_loss: 1.6960 - val_acc: 0.3824

Epoch 200/200 50000/50000 [==============================] - 612s - loss: 1.8005 - acc: 0.3497 - val_loss: 1.6164 - val_acc: 0.4041

I have two questions here:

  1. The accuracy (0.34/0.40) is too bad. Does anyone have similar problems?
  2. The shape of X_train as (50000, 32, 32, 3) seems strange to me because other keras/cifar examples give the shape of X_train as (50000, 3, 32, 32). If I add "set_image_dim_ordering('th')" to the code, the shape will become (50000, 3, 32, 32) but the program will give even lower accuracy as "Epoch 80/200 50000/50000 - 635s - loss: 14.5010 - acc: 0.1003 - val_loss: 14.5063 - val_acc: 0.1000" How to explain the effect of set dim here?

Thanks for any comments.

2

2 Answers

1
votes

That may not be the answer for the whole subject, but in order to get the correct image shape, you should just verify whether the image channel is the first or the last item of the shape. You can do it the following way, considering Keras 2:

from keras import backend as K

def image_input_shape(img_width, img_height):
    if K.image_data_format() == 'channels_first':
        input_shape = (3, img_width, img_height)
    else:
        input_shape = (img_width, img_height, 3)
    return input_shape

Just pass the image width and height and it will give back the correct ordering of the shape.

From there you can discard or validate you hypothesis for the "strange" shape.

0
votes

The problem I posted might be related to Keras 1.2.0 only. Since Keras has upgraded to 2.x and the official file cifar10_cnn.py has also changed, the problem I posted might not happen in new Keras. As a result, I would like to close this issue. Bytheway, one more piece info is that set_image_dim_ordering will create a different network architecture. The following output show the difference with this function and without this function.

Using Theano backend.
 with K.set_image_dim_ordering('th')

X_train shape: (50000L, 3L, 32L, 32L)
50000 train samples
10000 test samples
          InputLayer (None, 3L, 32L, 32L)
       Convolution2D (None, 32, 32L, 32L)
                Relu (None, 32, 32L, 32L)
       Convolution2D (None, 32, 30L, 30L)
                Relu (None, 32, 30L, 30L)
        MaxPooling2D (None, 32, 15L, 15L)
             Dropout (None, 32, 15L, 15L)
       Convolution2D (None, 64, 15L, 15L)
                Relu (None, 64, 15L, 15L)
       Convolution2D (None, 64, 13L, 13L)
                Relu (None, 64, 13L, 13L)
        MaxPooling2D (None, 64, 6L, 6L)
             Dropout (None, 64, 6L, 6L)
             Flatten (None, 2304)
               Dense (None, 512)
                Relu (None, 512)
             Dropout (None, 512)
               Dense (None, 10)
             Softmax (None, 10)

Using Theano backend.
 without K.set_image_dim_ordering('th')

X_train shape: (50000L, 32L, 32L, 3L)
50000 train samples
10000 test samples
          InputLayer (None, 32L, 32L, 3L)
       Convolution2D (None, 32L, 32L, 32)
                Relu (None, 32L, 32L, 32)
       Convolution2D (None, 30L, 30L, 32)
                Relu (None, 30L, 30L, 32)
        MaxPooling2D (None, 15L, 15L, 32)
             Dropout (None, 15L, 15L, 32)
       Convolution2D (None, 15L, 15L, 64)
                Relu (None, 15L, 15L, 64)
       Convolution2D (None, 13L, 13L, 64)
                Relu (None, 13L, 13L, 64)
        MaxPooling2D (None, 6L, 6L, 64)
             Dropout (None, 6L, 6L, 64)
             Flatten (None, 2304)
               Dense (None, 512)
                Relu (None, 512)
             Dropout (None, 512)
               Dense (None, 10)
             Softmax (None, 10)