[英]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.我正在试验tensorflow/models存储库提供的一些预训练模型。 The models are saved as .pb frozen graphs.
模型保存为 .pb 冻结图。 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.因此,我想将模型作为普通的 keras h5 模型加载到 jupyter 笔记本中。
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.
调用目录,例如 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.