Wboy
Wboy

Reputation: 2542

Keras cifar-10 Value error different tensorshape

I was following the standard cifar 10 keras tutorial here: https://github.com/fchollet/keras/blob/master/examples/cifar10_cnn.py

Which I modified to use my own training images. Each image replicates the dimensions of the cifar set, ie, they are each 32x32 and 3 channels.

Shape of each image:

(32,32,3)

However, I run into a ValueError as shown in the full output below.

X_train shape: (7200, 32, 32, 3)
7200 train samples
800 test samples
Using real-time data augmentation.
Epoch 1/200
Traceback (most recent call last):

  File "<ipython-input-16-70ca8831e139>", line 162, in <module>
    validation_data=(X_test, Y_test))

  File "/storage/programfiles/anaconda3/lib/python3.5/site-packages/keras/models.py", line 651, in fit_generator
    max_q_size=max_q_size)

  File "/storage/programfiles/anaconda3/lib/python3.5/site-packages/keras/engine/training.py", line 1383, in fit_generator
    class_weight=class_weight)

  File "/storage/programfiles/anaconda3/lib/python3.5/site-packages/keras/engine/training.py", line 1167, in train_on_batch
    outputs = self.train_function(ins)

  File "/storage/programfiles/anaconda3/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 659, in __call__
    updated = session.run(self.outputs + self.updates, feed_dict=feed_dict)

  File "/storage/programfiles/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 372, in run
    run_metadata_ptr)

  File "/storage/programfiles/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 625, in _run
    % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape())))

ValueError: Cannot feed value of shape (32, 32, 32, 3) for Tensor 'convolution2d_input_7:0', which has shape '(?, 3, 32, 32)'

Can anyone help me out? :)

EDIT: I tried reshaping as follows:

X_train = X_train.reshape((7200,3,32,32))
X_test = X_test.reshape((-1,3,32,32))

It crashed instead.

Upvotes: 0

Views: 227

Answers (1)

Mikael Rousson
Mikael Rousson

Reputation: 2267

You actually need to transpose your array to the correct ordering, not a reshape:

X_train = np.transpose(X_train, (0, 3, 1, 2))
X_test = np.transpose(X_test, (0, 3, 1, 2))

Upvotes: 0

Related Questions