1

我在这里测试 Keras 的作者的卷积自动编码器: https ://blog.keras.io/building-autoencoders-in-keras.html

但我有这个问题:

Exception: Error when checking model target: expected convolution2d_7 to have shape (None, 8, 32, 1) but got array with shape (60000, 1, 28, 28)

我准确地说,我已经在最后一个 conv 层中设置了字段 'border_mode='same''。所以我真的不知道它来自哪里..这是摘要:

Layer (type)                     Output Shape          Param #         Connected to                     
        ====================================================================================================
input_1 (InputLayer)             (None, 1, 28, 28)     0                                            
 ____________________________________________________________________________________________________
convolution2d_1 (Convolution2D)  (None, 1, 28, 16)     4048        input_1[0][0]                    
____________________________________________________________________________________________________
maxpooling2d_1 (MaxPooling2D)    (None, 1, 14, 16)     0           convolution2d_1[0][0]            
        ______________________________________________________________________________    ______________________
convolution2d_2 (Convolution2D)  (None, 1, 14, 8)      1160        maxpooling2d_1[0][0]             
____________________________________________________________________________________________________
maxpooling2d_2 (MaxPooling2D)    (None, 1, 7, 8)       0           convolution2d_2[0][0]            
____________________________________________________________________________________________________
convolution2d_3 (Convolution2D)  (None, 1, 7, 8)       584         maxpooling2d_2[0][0]             
____________________________________________________________________________________________________
maxpooling2d_3 (MaxPooling2D)    (None, 1, 4, 8)       0           convolution2d_3[0][0]            
____________________________________________________________________________________________________
convolution2d_4 (Convolution2D)  (None, 1, 4, 8)       584         maxpooling2d_3[0][0]             
____________________________________________________________________________________________________
upsampling2d_1 (UpSampling2D)    (None, 2, 8, 8)       0           convolution2d_4[0][0]            
 ____________________________________________________________________________________________________
convolution2d_5 (Convolution2D)  (None, 2, 8, 8)       584         upsampling2d_1[0][0]             
____________________________________________________________________________________________________
upsampling2d_2 (UpSampling2D)    (None, 4, 16, 8)      0           convolution2d_5[0][0]            
____________________________________________________________________________________________________
convolution2d_6 (Convolution2D)  (None, 4, 16, 16)     1168        upsampling2d_2[0][0]             
____________________________________________________________________________________________________
upsampling2d_3 (UpSampling2D)    (None, 8, 32, 16)     0           convolution2d_6[0][0]            
______________________________________________________________________________ ______________________

convolution2d_7 (Convolution2D)  (None, 8, 32, 1)      145             

upsampling2d_3[0][0]             
====================================================================================================
Total params: 8273
 ____________________________________________________________________________________________________
4

1 回答 1

3

终于找到了答案。我认为本教程的创建者使用 32x32 MNIST 图像而不是 28x28 对其进行了测试。

因为,当添加到最后一个 conv 层时,border_mode='same',你得到的输出形状为 (32,32,1) 所以,为了得到好的输出 (28,28,1) 你需要添加border_mode='valid ' 到最后一个 conv 层。

总结:将尺寸排序更正为 28x28x1 而不是 1x28x28。然后将边框模式添加到最后一个卷积层最后添加边框模式有效到最后一个卷积层。

希望这会有所帮助。

于 2016-12-27T15:54:41.430 回答