ageron / handson-ml2

A series of Jupyter notebooks that walk you through the fundamentals of Machine Learning and Deep Learning in Python using Scikit-Learn, Keras and TensorFlow 2.
Apache License 2.0
27.8k stars 12.74k forks source link

Chapter14 notebook: keras.applications.resnet50.decode_predictions() does not work #569

Open FatihMercan61 opened 2 years ago

FatihMercan61 commented 2 years ago

When I execute the following code from the notebook of chapter 14: (its the exact same code as in the notebook)

top_K = keras.applications.resnet50.decode_predictions(Y_proba, top=3)

I get the following error:

AttributeError: 'tensorflow.python.framework.ops.EagerTensor' object has no attribute 'argsort'
ageron commented 2 years ago

Thanks for your question, and sorry for the late reply.

In the previous cell, Y_proba is created like this:

Y_proba = model.predict(inputs)

The predict() method returns a NumPy array, which does have an argsort() method. I'm guessing you ran the following code instead:

Y_proba = model(inputs)

This would indeed return a TensorFlow tensor, which does not have an argsort() method.

The decode_predictions() method must try to call the argsort() method, hence the error.

If you use the predict() method, everything should work fine.

Hope this helps.