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

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

 Keras 报错AttributeError: ‘Sequential‘ object has no attribute ‘predict_classes‘解决方法(亲测正确解决方法)_第1张图片

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

1.没有使用汉堡式建模

2.tensorflow在2.6以上

Keras 报错AttributeError: ‘Sequential‘ object has no attribute ‘predict_classes‘解决方法(亲测正确解决方法)_第2张图片

解决方法:

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)

解决结果如图:

Keras 报错AttributeError: ‘Sequential‘ object has no attribute ‘predict_classes‘解决方法(亲测正确解决方法)_第3张图片

 欢迎补充总结。

你可能感兴趣的:(Tensorflow,兴趣分享,keras,深度学习,python,predict_class)