Skip to content

System.NotImplementedException : 'Model load of h5 format has not been supported #1024

Closed

Description

@Sylia-C

Hello,
I am trying to load a .h5 model with the load_model function (Tensorflow.Keras.Models) but I get this error
issue:
System.NotImplementedException : 'Model load of h5 format has not been supported. Please submit an issue to https://github.com/SciSharp/TensorFlow.NET/issues if it's needed.'

any suggestions please,
Thank you

Activity

  1. SanftMonster commented on Apr 15, 2023

    @SanftMonster
    Collaborator

    Hello, the loading of "h5" format keras model has not been supported. We has implemented the loading of "SavedModel" format first because it's recommended by tensorflow. The loading of "h5" format is also on our schedule but is not very urgent now. May I ask why you choose "h5" format instead of "SavedModel"?

  2. Sylia-C commented on Apr 15, 2023

    @Sylia-C
    Author

    Thank you for your answer, I chose the .h because it is a network that I have already trained in Python with tensorflow-keras, and since I work in c# I wanted to reuse it

  3. SanftMonster commented on Apr 15, 2023

    @SanftMonster
    Collaborator

    I see. The loading of "h5" format is a big feature and support of the loading complex models (such as bert) with "SavedModel" format has higher priority in tf.net. We will implement the loading of of "h5" format model in the future but it costs time. A possible alternative is loading your model in python and save it again to "SavedModel" format, then load it in C#. If your model contains self-defined keras module, please try after the merge of #1022, which added support for it.

  4. Sylia-C commented on Apr 19, 2023

    @Sylia-C
    Author

    hello,
    I followed your suggestions and loaded the .h model then saved it in savedModel (format.pb), so even I retrained the model and saved it in .pb format, but when I tried to test it I got following error:

    image

    the model attached

    saved_model.zip

    thanks

  5. Sylia-C commented on Apr 19, 2023

    @Sylia-C
    Author

    in python it loads normal (.h and .pb format) but in c# no

    import tensorflow as tf

    #import tensorflow.python.framework.convert_variables_to_constants_v2
    from tensorflow.python.keras.models import load_model
    from tensorflow.keras.models import Model
    model = tf.keras.models.load_model('mod/InceptionResNet/')
    print(model.summary())

  6. SanftMonster commented on Apr 20, 2023

    @SanftMonster
    Collaborator

    Hi, the file seems to be SavedModel format saved prior to TF 2.5. The loading itself is supported by using tf.saved_model.load. However it seems that your model has other parts such as restoring optimizer so it will still fail. I'll finish the lacked features in the next 2 or 3 days.

  7. Sylia-C commented on Apr 20, 2023

    @Sylia-C
    Author

    Hi, I used another savedModel conversion script, it solved my problem, attached the link so that others can benefit
    https://ksingh7.medium.com/part-iii-convert-keras-model-to-tensorflow-frozen-graph-model-a6aa6b1aaeee

    Thanks

  8. SanftMonster commented on Apr 20, 2023

    @SanftMonster
    Collaborator

    Hey, is the model converted by this script can be directly loaded by tf.net?

  9. Sylia-C commented on Apr 20, 2023

    @Sylia-C
    Author

    Yes

    image

  10. SanftMonster commented on Apr 20, 2023

    @SanftMonster
    Collaborator

    Yes

    image

    Thanks for your sharing. That's a very good work around. I'll still fix the bug of loading your uploaded model in this issue.

  11. SanftMonster commented on Apr 21, 2023

    @SanftMonster
    Collaborator

    hello, I followed your suggestions and loaded the .h model then saved it in savedModel (format.pb), so even I retrained the model and saved it in .pb format, but when I tried to test it I got following error:

    image

    the model attached

    saved_model.zip

    thanks

    #1032 supports this way by adding an API tf.saved_model.load. However both tensorflow and tf.net will throw an exception that no variable file is found. Did you remove this part in the uploaded file?

  12. Sylia-C commented on Apr 24, 2023

    @Sylia-C
    Author

    No, I didn't delete anything, as indicated above, I opted for a format.h5 conversion to frozen model.pb with a well-detailed tutorial.

  13. SanftMonster commented on Apr 24, 2023

    @SanftMonster
    Collaborator

    Did you succeed in tensorflow (python)? I tried loading the file with tensorflow python but failed, which tells me it cannot find variable files.

  14. Sylia-C commented on Apr 24, 2023

    @Sylia-C
    Author

    a problem with this model that I put in attachment, I use another model, basically I took my basic model .h5 convert to .pb, but the attached model is wrong

  15. SanftMonster commented on Apr 24, 2023

    @SanftMonster
    Collaborator

    Thanks, I'll close this issue as completed. Please don't hesitate to tell us if any problem in the future.

  16. jaroslav-hook commented on Jan 16, 2024

    @jaroslav-hook

    how about the loading a model? You seem to have implemented model.save , model.save_weights which saves the TF model.
    How about loading it ? Cannot find it.
    By the way , where why is model.predict() requires a different data format from model.fit()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementmodel save/load

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions