handson-ml2
handson-ml2 copied to clipboard
Chapter14 notebook: keras.applications.resnet50.decode_predictions() does not work
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'
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.