Keras 报错AttributeError: ‘Sequential‘ object has no attribute ‘predict_classes‘解决方法(亲测正确解决方法)

2022-09-27 09:17:17

Python Keras 报错AttributeError: 'Sequential' object has no attribute 'predict_classes'解决方法-CJavaPyhttps://www.cjavapy.com/article/2239/

 以上链接为对于该问题的解释以及图片,同时出现该问题原因如下:

1.没有使用汉堡式建模

2.tensorflow在2.6以上

解决方法:

predict_x=model.predict(X_test) 
classes_x=np.argmax(predict_x,axis=1)

错误的2种解决方法:

#1 sequential way only
#1 prediction = model.predict_classes(test_images) #结果预测 # old way 
#2 prediction = model.predict(test_images) # not use 
#2 prediction = np.int64(prediction>0.5)

解决结果如图:

 欢迎补充总结。

  • 作者:Victor__Zhang
  • 原文链接:https://blog.csdn.net/soga235/article/details/122134969
    更新时间:2022-09-27 09:17:17