简体   繁体   English

keras.models.save_model 中的 saved_model.pb 是否与 tensorflow freeze_graph output.pb 文件相同?

[英]Is saved_model.pb from keras.models.save_model the same with tensorflow freeze_graph output .pb file?

After a model is trained in keras, I used to apply tf.compat.v1.graph_util.convert_variables_to_constants or freeze_graph.py to freeze model and output .pb file. After a model is trained in keras, I used to apply tf.compat.v1.graph_util.convert_variables_to_constants or freeze_graph.py to freeze model and output .pb file. Like this:像这样:

output_graph_def = tf.compat.v1.graph_util.convert_variables_to_constants(sess, input_graph_def, output_node_names)
with tf.gfile.GFile('model.pb', "wb") as f:  
    f.write(output_graph_def.SerializeToString())

Recently, I find tf.compat.v1.graph_util.convert_variables_to_constants is labeled with: Warning: THIS FUNCTION IS DEPRECATED .最近,我发现tf.compat.v1.graph_util.convert_variables_to_constants标有: Warning: THIS FUNCTION IS DEPRECATED

So I'm looking for a updated method of generate .pb file.所以我正在寻找一种生成.pb文件的更新方法。 I find this: keras.models.save_model() to save model and output dir contains:我发现这个: keras.models.save_model()保存 model 和 output 目录包含:

assets saved_model.pb variables资产 saved_model.pb 变量

I'm not sure if this saved_model.pb is the same with output .pb file of tf.compat.v1.graph_util.convert_variables_to_constants ?我不确定这个saved_model.pb是否与 tf.compat.v1.graph_util.convert_variables_to_constants 的tf.compat.v1.graph_util.convert_variables_to_constants .pb文件相同?

If not, could someone recommed a better way to get frozen model (.pb) file?如果没有,有人可以推荐一种更好的方法来冻结 model (.pb) 文件吗?

Thanks.谢谢。

I have confirmed they are not the same.pb file.我已经确认它们不是同一个.pb 文件。 If you load and run SavedModel format, you'll get error: Data loss: Can't parse testmodel/saved_model.pb as binary proto如果你加载并运行 SavedModel 格式,你会得到错误: Data loss: Can't parse testmodel/saved_model.pb as binary proto

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 tf.Session 保存到 saved_model.pb? - How to save to saved_model.pb from tf.Session? 如何从 saved_model.pb 文件加载 model 架构和 model 权重? - How to load model architecture and model weights from saved_model.pb file? 如何正确创建saved_model.pb? - How to correctly create saved_model.pb? 如何在 TensorFlow 2.0 中冻结 keras model? (专门将一个保存的model格式冻结为.pb格式) - How to freeze a keras model in TensorFlow 2.0? (specifically freeze a saved model format to .pb format) frozen_inference_graph.pb 和saved_model.pb 有什么区别? - What is difference frozen_inference_graph.pb and saved_model.pb? 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) 将 tf1.x saved_model.pb 重新保存到新的 tf2.0 saved_model.pb - resave tf1.x saved_model.pb into new tf2.0 saved_model.pb OSError:SavedModel 文件不存在于:/content\model\2016/{saved_model.pbtxt|saved_model.pb} - OSError: SavedModel file does not exist at: /content\model\2016/{saved_model.pbtxt|saved_model.pb} 如何将具有自定义 keras 层(.h5)的 keras 模型冻结到张量流图(.pb)? - How to freeze a keras model with custom keras layers(.h5) to tensorflow graph(.pb)? Tensorflow 2.0 将 keras 模型转换为 .pb 文件 - Tensorflow 2.0 Convert keras model to .pb file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM