首页 文章

Python - 重塑不起作用

提问于
浏览
1

我正在使用 keras 训练CNN,基本错误是维度不匹配 .

原因,调试后是:

print("Before")
print(TX.shape)
print(TeX.shape)

X_train = TX.reshape(1000, 1, img_rows, img_cols)
X_test = TeX.reshape(430, 1, img_rows, img_cols)
print("After")
print(TX.shape)
print(TeX.shape)

生成输出:

Using Theano backend.
Using gpu device 0: GeForce GTX 750 Ti (CNMeM is disabled, CuDNN not available)
Before
(1000, 27, 36)
(430, 27, 36)
After
(1000, 27, 36)
(430, 27, 36)

如果需要,我的模型的总结是:

____________________________________________________________________________________________________

图层(类型)输出形状参数#连接到

convolution2d_1(Convolution2D)(无,32,25,34)320 convolution2d_input_1 [0] [0]


activation_1(激活)(无,32,25,34)0 convolution2d_1 [0] [0]


convolution2d_2(Convolution2D)(无,32,23,32)9248 activation_1 [0] [0]


activation_2(激活)(无,32,23,32)0 convolution2d_2 [0] [0]


convolution2d_3(Convolution2D)(无,32,21,30)9248 activation_2 [0] [0]


activation_3(激活)(无,32,21,30)0 convolution2d_3 [0] [0]


maxpooling2d_1(MaxPooling2D)(无,32,10,15)0 activation_3 [0] [0]


dropout_1(Dropout)(None,32,10,15)0 maxpooling2d_1 [0] [0]


flatten_1(展平)(无,4800)0 dropout_1 [0] [0]


dense_1(密集)(无,128)614528 flatten_1 [0] [0]


activation_4(激活)(无,128)0 dense_1 [0] [0]


dropout_2(Dropout)(无,128)0 activation_4 [0] [0]


dense_2(密集)(无,26)3354 dropout_2 [0] [0]


activation_5(激活)(无,26)0 dense_2 [0] [0]

总参数:636698


1 回答

  • 3

    您正在将重新整形的数组分配给新变量,但是您仍然在打印旧变量的形状:

    X_train = TX.reshape(..)
    

    你必须使用:

    print(X_train.shape)
    

相关问题