[英]How to convert .pb file to .h5. (Tensorflow model to keras)
I've retrained my model using tensorflow
and now want to use keras
to avoid session stuffs.我已经使用tensorflow
重新训练了我的模型,现在想使用keras
来避免会话问题。 How can I convert .pb
file to .h5
如何将.pb
文件转换为.h5
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')
I found this link useful: https://backstreetcoder.com/convert-tensorflow-pb-model-to-keras-h5-model/我发现这个链接很有用: 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.显然,在最初加载模型时,您需要使用封闭目录名称而不是 .pb 文件名。 This solves the error:这解决了错误:
SavedModel file does not exist at: saved_model_dir/{saved_model.pbtxt|saved_model.pb}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.