keras-team/keras-applications

AutoGraph could not transform model.make_predict_function ... and run it as-is.

RobinV760 opened this issue · 0 comments

Summary

Environment

  • Python version: 3.7
  • Keras version: 2.4.0
  • Keras-applications version: 1.0.8
  • Keras backend with version: not installed

Logs or source codes for reproduction

WARNING:tensorflow:AutoGraph could not transform <function Model.make_predict_function..predict_function at 0x000002251A6CB438> and will run it as-is.
Please report this to the TensorFlow team. When filing the bug, set the verbosity to 10 (on Linux, export AUTOGRAPH_VERBOSITY=10) and attach the full output.
Cause:

WARNING:tensorflow:Model was constructed with shape (None, 299, 299, 3) for input Tensor("input_7:0", shape=(None, 299, 299, 3), dtype=float32), but it was called on an input with incompatible shape (None, 224, 224, 3).

My code:

from keras.applications.inception_v3 import InceptionV3
from keras.preprocessing.image import load_img, img_to_array
from keras.applications.inception_v3 import preprocess_input, decode_predictions


# load model
model = InceptionV3()

# summarize the model
model.summary()

#%%

# load an image and make a prediction
image = load_img(("cat.jpg"), target_size = (224, 224))
image = img_to_array(image)
image = image.reshape((1, image.shape[0], image.shape[1], image.shape[2]))
image = preprocess_input(image)

yhat = model.predict(image)
label = decode_predictions(yhat)
print(label)
label = label[0][0] # highest probability
print('{} ({})'.format(label[1], label[2]*100))

Does it have to do with lower versions for keras.applications?
Also, I because of the error message about the incompatible shapes, I changed the target size of my input image to (299, 299), and to (416, 416).

For the same image, I got different predictions. For (416, 416): tiger_cat (6.228156387805939), for (299, 299): Egyptian_cat (55.72159290313721), for (224, 224): lynx (48.244667053222656).

I'll post about this on Stackoverflow though.