Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't Load Models in Tensorflow #1

Closed
chigkim opened this issue Nov 10, 2022 · 4 comments
Closed

Can't Load Models in Tensorflow #1

chigkim opened this issue Nov 10, 2022 · 4 comments

Comments

@chigkim
Copy link

chigkim commented Nov 10, 2022

Thanks so much for quick response on FigmaAI/zeplin-ml/issues/1!
I'm having a problem loading the models.
If I try to load using tf.keras.models.load_model("rico/models/mobilenetv2-50k/saved-model/saved_model"), it throws error below.

WARNING:tensorflow:SavedModel saved prior to TF 2.5 detected when loading Keras model. Please ensure that you are saving the model with model.save() or tf.keras.models.save_model(), *NOT* tf.saved_model.save(). To confirm, there should be a file named "keras_metadata.pb" in the SavedModel directory.
ValueError: Unable to create a Keras model from SavedModel at design-system-detector/rico/models/mobilenetv2-50k/saved-model/saved_model. This SavedModel was exported with `tf.saved_model.save`, and lacks the Keras metadata file. Please save your Keras model by calling `model.save` or `tf.keras.models.save_model`.
 Note that you can still load this SavedModel with `tf.saved_model.load`.

If I load with tf.saved_model.load, it just returns _UserObject, and I can't run model.predict.
AttributeError: '_UserObject' object has no attribute 'predict'
Is that possible for you to resave models, so people can load them in recent Tensorflow?
Thanks for your help!

@dusskapark
Copy link
Collaborator

dusskapark commented Nov 11, 2022 via email

@chigkim
Copy link
Author

chigkim commented Nov 11, 2022

Actually I tried loading it with Tensorflow 2.5, 2.4, 2.3, 2.2 with no luck. I get this error.

raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Do you have any code snippet I can look on Colab or Kaggle for inferencing or fine tuning on Tensorflow, not Tensorflow.js?
Thank you so much for your help

@dusskapark
Copy link
Collaborator

dusskapark commented Nov 11, 2022 via email

@chigkim
Copy link
Author

chigkim commented Nov 12, 2022

Thank you!!!
I was able to get it going in Tensorflow 2.10.0.
In case other people are interested, here's a little snippet to predict one image file.

import tensorflow as tf
from tensorflow.keras.utils import load_img, img_to_array
import numpy as np

model_dir = "design-system-detector/rico/models/mobilenetv2-50k/saved-model/saved_model"
model = tf.saved_model.load(model_dir)
model = model.signatures['serving_default']
img = load_img("rico/combined/100.jpg")
img = img_to_array(img, dtype=np.uint8)[np.newaxis,...]
input_tensor = tf.convert_to_tensor(img)
output_dict = model(input_tensor=input_tensor)
classes = np.array(output_dict['detection_classes'])
boxes = np.array(output_dict['detection_boxes'])
scores = np.array(output_dict['detection_scores'])
print(classes.shape, classes.dtype)
print(boxes.shape, boxes.dtype)
print(scores.shape, scores.dtype)

@chigkim chigkim closed this as completed Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants