Python - 重塑不起作用
Python - Reshape not working
我正在使用 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) (None, 32, 25, 34) 320 convolution2d_input_1[0][0]
activation_1(激活)(None, 32, 25, 34) 0 convolution2d_1[0][0]
convolution2d_2 (Convolution2D) (None, 32, 23, 32) 9248 activation_1[0][0]
activation_2(激活)(None, 32, 23, 32) 0 convolution2d_2[0][0]
convolution2d_3 (Convolution2D) (None, 32, 21, 30) 9248 activation_2[0][0]
activation_3(激活)(None, 32, 21, 30) 0 convolution2d_3[0][0]
maxpooling2d_1 (MaxPooling2D) (None, 32, 10, 15) 0 activation_3[0][0]
dropout_1(辍学)(None, 32, 10, 15) 0 maxpooling2d_1[0][0]
flatten_1(展平)(None, 4800) 0 dropout_1[0][0]
dense_1(密集)(None, 128) 614528 flatten_1[0][0]
activation_4(激活)(None, 128) 0 dense_1[0][0]
dropout_2 (辍学) (None, 128) 0 activation_4[0][0]
dense_2 (密集) (None, 26) 3354 dropout_2[0][0]
activation_5(激活)(None, 26) 0 dense_2[0][0]
总参数:636698
您正在将重塑后的数组分配给一个新变量,但您仍在打印旧变量的形状:
X_train = TX.reshape(..)
您必须使用:
print(X_train.shape)
我正在使用 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) (None, 32, 25, 34) 320 convolution2d_input_1[0][0]
activation_1(激活)(None, 32, 25, 34) 0 convolution2d_1[0][0]
convolution2d_2 (Convolution2D) (None, 32, 23, 32) 9248 activation_1[0][0]
activation_2(激活)(None, 32, 23, 32) 0 convolution2d_2[0][0]
convolution2d_3 (Convolution2D) (None, 32, 21, 30) 9248 activation_2[0][0]
activation_3(激活)(None, 32, 21, 30) 0 convolution2d_3[0][0]
maxpooling2d_1 (MaxPooling2D) (None, 32, 10, 15) 0 activation_3[0][0]
dropout_1(辍学)(None, 32, 10, 15) 0 maxpooling2d_1[0][0]
flatten_1(展平)(None, 4800) 0 dropout_1[0][0]
dense_1(密集)(None, 128) 614528 flatten_1[0][0]
activation_4(激活)(None, 128) 0 dense_1[0][0]
dropout_2 (辍学) (None, 128) 0 activation_4[0][0]
dense_2 (密集) (None, 26) 3354 dropout_2[0][0]
activation_5(激活)(None, 26) 0 dense_2[0][0]
总参数:636698
您正在将重塑后的数组分配给一个新变量,但您仍在打印旧变量的形状:
X_train = TX.reshape(..)
您必须使用:
print(X_train.shape)