trainData。=(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。=(25000,),,形状如下:
[1. 1. 1. ... 0. 0. 0.]
使用它们来训练MLP模型,我应该做什么?具体代码如下:
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)
我应该如何重塑trainData和trainLabel ?请帮助。 问题来源StackOverflow 地址:/questions/59466678/error-when-checking-input-expected-dense-1-input-to-have-2-dimensions-but-got
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)
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。