大家好,有人对Keras很熟悉吗?我不明白问题出在哪里?我遇到了这个问题:
ValueError: You are passing a target array of shape (1000, 1) while using as loss `categorical_crossentropy`. `categorical_crossentropy` expects targets to be binary matrices (1s and 0s) of shape (samples, classes). If your targets are integer classes, you can convert them to the expected format via...from keras.utils import to_categoricaly_binary = to_categorical(y_int)Alternatively, you can use the loss function ` sparse_categorical_crossentropy` instead, which does expect integer targets.
这是完整的代码:https://ideone.com/v9yojt
回答:
将categorical_crossentropy
更改为binary_crossentropy
在第83行设置:
model.compile(loss='binary_crossentropy', optimizer="sgd", metrics=['accuracy'])