You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.NotImplementedException : 'Model load of h5 format has not been supported #1024
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.'
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"?
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
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.
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:
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())
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.
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:
#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?
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
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()?
Activity
SanftMonster commentedon Apr 15, 2023
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"?
Sylia-C commentedon Apr 15, 2023
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
SanftMonster commentedon Apr 15, 2023
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.
Sylia-C commentedon Apr 19, 2023
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:
the model attached
saved_model.zip
thanks
Sylia-C commentedon Apr 19, 2023
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())
SanftMonster commentedon Apr 20, 2023
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.Sylia-C commentedon Apr 20, 2023
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
SanftMonster commentedon Apr 20, 2023
Hey, is the model converted by this script can be directly loaded by tf.net?
Sylia-C commentedon Apr 20, 2023
Yes
SanftMonster commentedon Apr 20, 2023
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.
SanftMonster commentedon Apr 21, 2023
#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?Sylia-C commentedon Apr 24, 2023
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.
SanftMonster commentedon Apr 24, 2023
Did you succeed in tensorflow (python)? I tried loading the file with tensorflow python but failed, which tells me it cannot find variable files.
Sylia-C commentedon Apr 24, 2023
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
SanftMonster commentedon Apr 24, 2023
Thanks, I'll close this issue as completed. Please don't hesitate to tell us if any problem in the future.
jaroslav-hook commentedon Jan 16, 2024
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()?