![](/img/trans.png)
[英]Error when checking input: expected dense_1_input to have 5 dimensions, but got array with shape (1746, 131072)
[英]Error when checking input: expected dense_1_input to have 2 dimensions, but got array with shape (25000, 700, 50)
trainData.shape = (25000, 700, 50) ,形狀如下:
[[[ 0.7095 0.863 0.712 ... 0.02715 -1.305 0.5195 ]
[-0.66 1.715 -1.934 ... 0.5684 0.754 0.2593 ]
[-0.3533 2.256 -1.292 ... -0.2708 0.6714 -1.128 ]
...
[ 0. 0. 0. ... 0. 0. 0. ]
[ 0. 0. 0. ... 0. 0. 0. ]
[ 0. 0. 0. ... 0. 0. 0. ]]
...
trainLabel.shape = (25000,) , , 形狀如下:
[1. 1. 1. ... 0. 0. 0.]
使用它們來訓練 MLP 模型,我應該如何重塑 trainData 和 trainLabel ? 詳細代碼如下:
def MySimpleMLP(feature=700, vec_size=50):
auc_roc = LSTM.as_keras_metric(tf.compat.v1.metrics.auc)
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=(feature * vec_size,)))
model.add(Dropout(0.2))
model.add(Dense(32, activation='relu'))
model.add(Dropout(0.2))
model.add(Dense(1, activation='softmax'))
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=[auc_roc])
return model
......
model.fit(trainData, trainLabel, validation_split=0.2, epochs=10, batch_size=64, verbose=2)
請幫忙。
嘗試添加一個Flatten
層,如下所示:
def MySimpleMLP(feature=700, vec_size=50):
auc_roc = LSTM.as_keras_metric(tf.compat.v1.metrics.auc)
model = Sequential()
model.add(Dense(32, activation='relu', input_shape=(feature * vec_size,)))
model.add(Dropout(0.2))
model.add(Dense(32, activation='relu'))
model.add(Flatten())
model.add(Dropout(0.2))
model.add(Dense(1, activation='softmax'))
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=[auc_roc])
return model
......
model.fit(trainData, trainLabel, validation_split=0.2, epochs=10, batch_size=64, verbose=2)
Flatten
將 (num_of_samples, 64, 32, 32) 數組轉換為 (num_of_samples, 64 32 32) 數組,即它使數組為 2D,這正是您所需要的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.