I was trying to convert custom trained yolov5s model to tensorflow model for only predict.
First, converting yolov5s to onnx model was successful by running export.py, and to tensorflow representation too.
Pb folder created, and there are assets(but just empty folder), variables folder and saved_model.pb file.
With them, I used tf.keras.models.load_model, the type of model was _UserObject.
I cannot use summary, predict because the model is _UserObject.
Hi @human Can you share some of the code here, so the community can try to debug it with you? So the issue is, based on your description, is that, after the onnx-tf conversion, you can’t use either tf.keras.Model's summary or predict.
Okay, so there are two flavors of saved_model: “vanilla” and “keras”.
Vanilla only has the basic TensorFlow constructs (functions, variables).
The “keras” flavored ones also have all the metadata required to rebuild the keras objects.
It can’t automatically uncompile the low-level representation up into a higher-level keras representation.
tf.keras.models.load_model should be printing a warning that there’s no keras metadata available in that saved_model. IIRC, future versions of tensorflow will fail if you use tf.keras.models.load_model on a saved_model that doesn’t have it.
Use tf.saved_model.load. It will return the same _UserObect. Inspect that that to find your functions. does it have a .signatures attirbute?
AttributeError: '_UserObject' object has no attribute 'summary'
It looks like both keras.models.load_model will also load either flavor, and just fall-back to the non-keras _UserObject if the saved_model directory doesn’t contain the keras metadata required to load it as a keras.Model