解决Python报错‘Sequential‘ object has no attribute ‘predict_classes‘

python运行报错:

报错内容:‘Sequential’ object has no attribute ‘predict_classes’

在这里插入图片描述

原因:

在Tensorflow2.6之前的版本中拥有predict_class属性,之后版本已经取消。

解决办法

替换代码(自行对照代码修改参数即可)。如下:

(1)原代码

model = load_model('020_mnist_model.h5')
result = model.predict_classes(x_test[0].reshape(1,784)) 
result

(2)修改后代码

result = model.predict(x_test[0].reshape(1,784))
result = np.argmax(result, axis=1)
result

测试

可以正常输出结果,完成。
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/qq_43750528/article/details/128121844