I've retrained my model using tensorflow and now want to use keras to avoid session stuffs. How can I convert .pb file to .h5
2 Answers
import tensorflow as tf from tensorflow.keras.models import save_model, Sequential model_path = r"c:\temp\model.pb" model = tf.keras.models.load_model(model_path) save_model(model,model_path + r"\new_model.h5", save_format='h5') 6 Comments
BDL
Although this code might solve the problem, a good answer should explain what the code does and how it helps.
nivpeled
@BDL generally I tend to agree, but in this specific case I am pretty sure the code is self explanatory. i.e. "tf.keras.models.load_model" will load a tensor flow model, while save_model with argument save_format='h5' will, hmmm, save it as an h5 keras file.
H.H
@nivpeled I tried same code and got AttributeError: '_UserObject' object has no attribute '_is_graph_network'
AnupamChugh
I get OSError: SavedModel file does not exist at: saved_model_dir/{saved_model.pbtxt|saved_model.pb} error
maryam mehboob
AttributeError: 'AutoTrackable' object has no attribute '_is_graph_network' .I am also getting this error, have you solved?
|
I found this link useful: https://backstreetcoder.com/convert-tensorflow-pb-model-to-keras-h5-model/
Apparently, you need to use the enclosing directory name and not the .pb filename when loading the model initially. This solves the error:
SavedModel file does not exist at: saved_model_dir/{saved_model.pbtxt|saved_model.pb}