Failing to export a SavedModel downloaded from hub to h5

Hi,

I would like to export a SavedModel downloaded from hub to h5, however I am hitting several issues:

  1. I can’t export the model directly:
    Here is the code:
import tensorflow as tf

model = tf.saved_model.load('./model_zoo/retinanet_resnet50_v1_fpn_640x640_1')
model.save('./model_zoo/retinanet_resnet50_v1_fpn_640x640_1.h5')

And here is the error:

  File "./hubtest", line 115, in <module>
    model.save('./model_zoo/retinanet_resnet50_v1_fpn_640x640_1.h5')
AttributeError: '_UserObject' object has no attribute 'save'

From this github issue it seems that the keras API isn’t available on the loaded model, so I tried the following workaround:

  1. I can’t get the input spec to match
import tensorflow as tf
input = tf.keras.Input(shape=(None, None, 3), batch_size=1, dtype=tf.dtypes.uint8),
outputs =  hub.KerasLayer('./model_zoo/retinanet_resnet50_v1_fpn_640x640_1')(input)
# I can't use Sequential as the model is multi output
model = tf.keras.Model(inputs=input, outputs=outputs)
model.save('./model_zoo/retinanet_resnet50_v1_fpn_640x640_1.h5')

And the error:

ValueError: Exception encountered when calling layer "keras_layer" (type KerasLayer).

in user code:

    File "/home/tfprime/python3-venv/lib/python3.8/site-packages/tensorflow_hub/keras_layer.py", line 229, in call  *
        result = f()

    ValueError: Python inputs incompatible with input_signature:
      inputs: (
        (<tf.Tensor 'Placeholder:0' shape=(1, None, None, 3) dtype=uint8>,))
      input_signature: (
        TensorSpec(shape=(1, None, None, 3), dtype=tf.uint8, name=None)).


Call arguments received:
  • inputs=('tf.Tensor(shape=(1, None, None, 3), dtype=uint8)',)
  • training=None

Am I missing something?

This line:

has a trailing comma in the end. Remove it and everything works (just tested here)

thanks @markdaoust for the eagle eyes!!!

1 Like

This post was flagged by the community and is temporarily hidden.

Thanks, that was the issue.
I feel terrible for letting you debug a typo!
Thank you

1 Like