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
测试
可以正常输出结果,完成。