我有一个应用train_test_split
的数据集。 X的形状:
print(X_train.shape)
print(X_test.shape)
输出:
(1945, 10000)
(487, 10000)
由于X是numpy数组,因此需要将其转换为图像(3D),以便稍后使用神经网络。因此,我申请了:
X_train_3d = X_train.reshape(X_train.shape[0],100,100).astype('float32') # X_train.shape[1] = 10000 ;
# where 10000 = 100*100;
X_test_3d = X_test.reshape(X_test.shape[0],100,100).astype('float32')
print(X_train_3d.shape)
print(X_test_3d.shape)
所以,我得到了预期的结果:
(1945, 100, 100)
(487, 100, 100)
而且我以这种方式建立了神经网络:
model = keras.Sequential([
keras.layers.Flatten(input_shape=(100, 100)), # width, height of image 100,100
keras.layers.Dense(128, activation='relu'),
keras.layers.Dense(39) # total number of target = 39
])
model.compile(optimizer='adam',
loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
metrics=['accuracy'])
model.fit(X_train_3d, y_train, epochs=10)
现在,我正在使用数据集并尝试应用类似的逻辑。分割后:
print(X_train.shape)
print(X_test.shape)
输出:
(1945, 1800)
(487, 1800)
现在,我不知道如何定义像这样的重塑形状:
X_train_3d = X_train.reshape(X_train.shape[0],?,?).astype('float32')
因为1800的平方根不是整数。如何将其转换为3d,以便能够像以前一样构建神经网络。
进行此运行的唯一方法是不使用CNN。然后,您不必重塑。投机重塑只会产生随机像素。