close

[Solved] Keras AttributeError: ‘Sequential’ object has no attribute ‘predict_classes’

Hello Guys, How are you all? Hope You all Are Fine. Today I am Just using Sequential() and its method predict_classes but I am facing the following error Keras AttributeError: ‘Sequential’ object has no attribute ‘predict_classes’ in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How Keras AttributeError: ‘Sequential’ object has no attribute ‘predict_classes’ Error Occurs ?

I am Just using Sequential() and its method predict_classes but I am facing the following error.

Keras AttributeError: 'Sequential' object has no attribute 'predict_classes'

Here is my code.

sqntl = Sequential()

prediction = sqntl.predict_classes(X_test)

How To Solve Keras AttributeError: ‘Sequential’ object has no attribute ‘predict_classes’ Error ?

  1. How To Solve Keras AttributeError: 'Sequential' object has no attribute 'predict_classes' Error?

    To Solve Keras AttributeError: 'Sequential' object has no attribute 'predict_classes' Error These functions were removed in Tensorflow version 2.6. See details for how to update your code. Just update to. predict_x=model.predict(X_test)classes_x=np.argmax(predict_x,axis=1)

  2. Keras AttributeError: 'Sequential' object has no attribute 'predict_classes'

    To Solve Keras AttributeError: 'Sequential' object has no attribute 'predict_classes' Error These functions were removed in Tensorflow version 2.6. See details for how to update your code. Just update to. predict_x=model.predict(X_test)classes_x=np.argmax(predict_x,axis=1)

Solution 1: These functions were removed in Tensorflow version 2.6

These functions were removed in Tensorflow version 2.6. See details for how to update your code. Just update to.

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

Solution 2: Use TensorFlow 2.5 or later

As per Solution 1, Those functions were removed in Tensorflow version 2.6. So that temporary solution is you can use TensorFlow 2.5 or later.

Also If you will use TensorFlow 2.5 or later you will face the following warning.

tensorflow\python\keras\engine\sequential.py:455: UserWarning: model.predict_classes() is deprecated and will be removed after 2021-01-01. 

Please use instead:* np.argmax(model.predict(x), axis=-1), if your model does multi-class classification (e.g. if it uses a softmax last-layer activation).* (model.predict(x) > 0.5).astype("int32"), if your model does binary classification (e.g. if it uses a sigmoid last-layer activation).

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Also, Read

Please Rate Our Solution to Motivate Us For Give Our Best

Leave a Comment