0
我具有以下形狀的列車數據集:(300, 5, 720)
卷積神經網絡input_shape尺寸誤差(KERAS,PYTHON)
[[[ 6. 11. 389. ..., 0. 0. 0.]
[ 2. 0. 0. ..., 62. 0. 0.]
[ 0. 0. 18. ..., 0. 0. 0.]
[ 38. 201. 47. ..., 0. 108. 0.]
[ 0. 0. 1. ..., 0. 0. 0.]]
[[ 136. 95. 0. ..., 0. 0. 0.]
[ 85. 88. 85. ..., 0. 31. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 13. 19. 0. ..., 0. 0. 0.]]]
我試圖通過每個樣品輸入到CNN模型中,每個輸入是大小(5,720)
,我使用在keras以下模型:
cnn = Sequential()
cnn.add(Conv2D(64, (5, 50),
padding="same",
activation="relu",data_format="channels_last",
input_shape=in_shape))
cnn.add(MaxPooling2D(pool_size=(2,2),data_format="channels_last"))
cnn.add(Flatten())
cnn.add(Dropout(0.5))
cnn.add(Dense(number_of_classes, activation="softmax"))
cnn.compile(loss="categorical_crossentropy", optimizer="adam", metrics=
['accuracy'])
cnn.fit(x_train, y_train,
batch_size=batch_size,
epochs=epochs,
validation_data=(x_test, y_test),
shuffle=True)
我使用輸入的形狀爲:
rows,cols=x_train.shape[1:]
in_shape=(rows,cols,1)
,但我收到以下錯誤:
ValueError: Error when checking model input: expected conv2d_1_input to have 4 dimensions, but got array with shape (300, 5, 720)
如何解決這個問題?