简体   繁体   English

如何将 .pb 文件转换为 .h5。 (Tensorflow 模型到 keras)

[英]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.

相关问题 Tensorflow 2.0 将 keras 模型转换为 .pb 文件 - Tensorflow 2.0 Convert keras model to .pb file 如何将预训练的 tensorflow pb 冻结图转换为可修改的 h5 keras 模型? - How to convert a pretrained tensorflow pb frozen graph into a modifiable h5 keras model? Convert a Tensorflow model in SavedModel format (.pb file) saved with tf.saved_model.save to a Keras model (.h5 file) - Convert a Tensorflow model in SavedModel format (.pb file) saved with tf.saved_model.save to a Keras model (.h5 file) 如何将 Keras.h5 导出为 tensorflow.pb? - How to export Keras .h5 to tensorflow .pb? 如何将具有自定义 keras 层(.h5)的 keras 模型冻结到张量流图(.pb)? - How to freeze a keras model with custom keras layers(.h5) to tensorflow graph(.pb)? 如何将keras模型转换为协议缓冲区(.pb)文件? - How do I convert a keras model into a protocol buffer (.pb) file? 将keras h5转换为tensorflow pb以进行批处理推断 - convert keras h5 to tensorflow pb for batch inference 如何将 .h5 文件转换为 .pb 文件? - how to convert .h5 file to .pb file? 如何在TensorFlow中使用Estimator将模型存储在`.pb`文件中? - How to store model in `.pb` file with Estimator in TensorFlow? 如何使用 mmconvert 将 tensorflow 模型(InceptionResnetV2 pb 文件)转换为 pytorch 模型? - How to convert tensorflow model (InceptionResnetV2 pb file) to pytorch model using mmconvert?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM