handson-ml2 icon indicating copy to clipboard operation
handson-ml2 copied to clipboard

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

Open FatihMercan61 opened this issue 3 years ago • 1 comments

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'

FatihMercan61 avatar Jun 17 '22 22:06 FatihMercan61

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.

ageron avatar Sep 27 '22 23:09 ageron