简体   繁体   中英

How to convert a pretrained tensorflow pb frozen graph into a modifiable h5 keras model?

I have been searching for a method to do this for so long, and I can not find an answer. Most threads I found are of people wanting to do the opposite.

Backstory:

I am experimenting with some pre-trained models provided by the tensorflow/models repository. The models are saved as .pb frozen graphs. I want to fine-tune some of these models by changing the final layers to suit my application.

Hence, I want to load the models inside a jupyter notebook as a normal keras h5 model.

How can I do that? do you have a better way to do so?

Thanks.

seems like all you would have to do is download the model files and store them in a directory. Call the directory for example c:\\models. Then load the model.

model = tf.keras.models.load_model(r'c:\models')
model.summary()  # prints out the model layers
# generate code to modify the model as you typically do for transfer learning
# compile  the changed model
# train the model
# save the trained model as a .h5 file
dir=r'path to the directory you want to save the model to'
model_identifier= 'abcd.h5' # for abcd use whatever  identification you want
save_path=os.path.join(dir, model_identifier)
model.save(save_path)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM