model.add(Convolution2D(64, 3, 3, border_mode='same', input_shape=(32, 32, 3)))
model.add(Activation('relu'))
model.add(Convolution2D(32, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Convolution2D(64, 3, 3, border_mode='same'))
model.add(Activation('relu'))
model.add(Convolution2D(64, 3, 3))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Dropout(0.25))
model.add(Flatten())
model.add(Dense(512))
model.add(Activation('relu'))
model.add(Dropout(0.5))
model.add(Dense(10))
model.add(Activation('softmax'))
这是错误
ValueError Traceback (most recent call last)
<ipython-input-21-a60216c72b54> in <module>()
----> 1 model.add(Convolution2D(64, 3, 3, border_mode='same', input_shape=(3, 32, 32)))
2 model.add(Activation('relu'))
3 model.add(Convolution2D(32, 3, 3))
4 model.add(Activation('relu'))
5 model.add(MaxPooling2D(pool_size=(2, 2)))
/home/pranshu_44/anaconda3/lib/python3.5/site-packages/keras/models.py in add(self, layer)
330 output_shapes=[self.outputs[0]._keras_shape])
331 else:
--> 332 output_tensor = layer(self.outputs[0])
333 if isinstance(output_tensor, list):
334 raise TypeError('All layers in a Sequential model '
/home/pranshu_44/anaconda3/lib/python3.5/site-packages/keras/engine/topology.py in __call__(self, x, mask)
527 # Raise exceptions in case the input is not compatible
528 # with the input_spec specified in the layer constructor.
--> 529 self.assert_input_compatibility(x)
530
531 # Collect input shapes to build layer.
/home/pranshu_44/anaconda3/lib/python3.5/site-packages/keras/engine/topology.py in assert_input_compatibility(self, input)
467 self.name + ': expected ndim=' +
468 str(spec.ndim) + ', found ndim=' +
--> 469 str(K.ndim(x)))
470 if spec.dtype is not None:
471 if K.dtype(x) != spec.dtype:
ValueError: Input 0 is incompatible with layer convolution2d_11: expected ndim=4, found ndim=2
我正在尝试对 cifar 10 进行图像分类,但根据 do docs [ https://keras.io/layers/convolutional/][1]我得到了这个错误我的答案是正确的,但我不知道为什么我收到此错误
- 我应该使用(无,32,32,3)尺寸吗