且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Keras精度不变

更新时间:2023-12-02 22:00:40

最可能的原因是优化器不适合您的数据集.这是文档中的 Keras优化器的列表.

The most likely reason is that the optimizer is not suited to your dataset. Here is a list of Keras optimizers from the documentation.

我建议您首先尝试使用默认参数值的SGD.如果仍然不起作用,请将学习率除以10.如有必要,请重复几次.如果您的学习率达到1e-6并且仍然无法正常工作,那么您还有另一个问题.

I recommend you first try SGD with default parameter values. If it still doesn't work, divide the learning rate by 10. Do that a few times if necessary. If your learning rate reaches 1e-6 and it still doesn't work, then you have another problem.

总而言之,替换此行:

model.compile(loss = "categorical_crossentropy", optimizer = "adam")

与此:

from keras.optimizers import SGD
opt = SGD(lr=0.01)
model.compile(loss = "categorical_crossentropy", optimizer = opt)

,如果不起作用,请更改几次学习率.

and change the learning rate a few times if it doesn't work.

如果是问题所在,那么您应该会看到损失仅在短短几个时期后就降低了.

If it was the problem, you should see the loss getting lower after just a few epochs.