Ado*_*orn 3 python neural-network theano deep-learning keras
我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)
Run Code Online (Sandbox Code Playgroud)
生成输出:
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)
Run Code Online (Sandbox Code Playgroud)
如果需要,我的模型摘要是:
____________________________________________________________________________________________________
Run Code Online (Sandbox Code Playgroud)
卷积2d_1 (Convolution2D) (None, 32, 25, 34) 320 卷积2d_input_1[0][0]
activation_1 (Activation) (None, 32, 25, 34) 0 卷积2d_1[0][0]
卷积2d_2 (Convolution2D) (None, 32, 23, 32) 9248 activation_1[0][0]
activation_2 (Activation) (None, 32, 23, 32) 0 卷积2d_2[0][0]
卷积2d_3 (Convolution2D) (None, 32, 21, 30) 9248 activation_2[0][0]
activation_3 (Activation) (None, 32, 21, 30) 0 卷积2d_3[0][0]
maxpooling2d_1 (MaxPooling2D) (None, 32, 10, 15) 0 activation_3[0][0]
dropout_1 (Dropout) (None, 32, 10, 15) 0 maxpooling2d_1[0][0]
flatten_1 (Flatten) (None, 4800) 0 dropout_1[0][0]
密集_1(密集)(无,128)614528 flatten_1[0][0]
激活_4(激活)(无,128)0dense_1[0][0]
dropout_2 (Dropout) (None, 128) 0 activation_4[0][0]
密集_2(密集)(无,26)3354 dropout_2[0][0]
总参数:636698
小智 5
您正在将重新整形的数组分配给一个新变量,但随后您仍在打印旧变量的形状:
X_train = TX.reshape(..)
Run Code Online (Sandbox Code Playgroud)
您必须使用:
print(X_train.shape)
Run Code Online (Sandbox Code Playgroud)