Keras cifar-10值误差不同tensorshape

时间:2016-07-06 16:30:05

标签: tensorflow keras

我在这里遵循标准的cifar 10 keras教程:https://github.com/fchollet/keras/blob/master/examples/cifar10_cnn.py

我修改了使用自己的训练图像。每个图像都复制了cifar集的尺寸,即它们分别是32x32和3个通道。

每张图片的形状:

(32,32,3)

但是,我遇到了一个ValueError,如下面的完整输出所示。

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)'

任何人都可以帮助我吗? :)

编辑: 我尝试重塑如下:

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

它崩溃了。

1 个答案:

答案 0 :(得分:0)

您实际上需要将数组转置为正确的顺序,而不是重塑:

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