gpt4 book ai didi

python - Keras假形,

转载 作者:行者123 更新时间:2023-11-30 08:57:33 25 4
gpt4 key购买 nike

嗨,有人了解 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.

Hieer是完整的代码: https://ideone.com/v9yojt

最佳答案

categorical_crossentropy更改为binary_crossentropy

第 83 行设置:

model.compile(loss='binary_crossentropy', optimizer="sgd", metrics=['accuracy'])

关于python - Keras假形,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53702456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com