新手问题:Keras 形状不兼容

Noob question: Keras shapes are incompatible

我是一名数据科学专业的学生,​​我正在尝试使用深度学习。我的模型如下:

Model: "sequential_32"

Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_26 (Conv2D)           (None, 27, 27, 32)        288       
_________________________________________________________________
max_pooling2d_12 (MaxPooling (None, 13, 13, 32)        0         
_________________________________________________________________
dense_13 (Dense)             (None, 13, 13, 128)       4224      
_________________________________________________________________
dropout_6 (Dropout)          (None, 13, 13, 128)       0         
_________________________________________________________________
dense_14 (Dense)             (None, 13, 13, 10)        1290      
=================================================================
Total params: 5,802
Trainable params: 5,802
Non-trainable params: 0
_________________________________________________________________

现在我尝试使用以下代码将一些数据放入其中:

print(x_train.shape)
print(x_test.shape)
result = model.fit(x_train, y_train,
          batch_size=batch_size,
          epochs=epochs,
          verbose=1,
          validation_data=(x_test, y_test))

输出如下:

(60000, 28, 28, 1)
(10000, 28, 28, 1)
# some error codes followed by:
ValueError: Shapes (32, 10) and (32, 13, 13, 11) are incompatible

我觉得这确实是一个很容易改正的错误,但我就是看不出来。欢迎任何帮助和/或解释!

是的,Thymen 的回复帮助了我。谢谢你。该模型现在看起来像这样:

Model: "sequential_35"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_29 (Conv2D)           (None, 27, 27, 32)        160       
_________________________________________________________________
max_pooling2d_15 (MaxPooling (None, 13, 13, 32)        0         
_________________________________________________________________
flatten (Flatten)            (None, 5408)              0         
_________________________________________________________________
dense_17 (Dense)             (None, 128)               692352    
_________________________________________________________________
dropout_8 (Dropout)          (None, 128)               0         
_________________________________________________________________
dense_18 (Dense)             (None, 10)                1290      
=================================================================
Total params: 693,802
Trainable params: 693,802
Non-trainable params: 0
_________________________________________________________________