Nas*_* Kr 2 python machine-learning neural-network python-3.x keras
嗨,有人知道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_categorical
y_binary = to_categorical(y_int)
Alternatively, you can use the loss function `
sparse_categorical_crossentropy` instead, which does expect integer targets.
Run Code Online (Sandbox Code Playgroud)
Hieer是完整代码:https ://ideone.com/v9yojt
改变categorical_crossentropy与binary_crossentropy
在第 83 行中设置:
model.compile(loss='binary_crossentropy', optimizer="sgd", metrics=['accuracy'])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2579 次 |
| 最近记录: |