[英]How to convert .ckpt to .pb?
I am new to deep learning and I want to use a pretrained (EAST) model to serve from the AI Platform Serving, I have these files made available by the developer:我是深度学习的新手,我想使用预训练 (EAST) 模型从 AI Platform Serving 提供服务,开发人员提供了以下文件:
I want to convert it into the TensorFlow .pb
format.我想将其转换为 TensorFlow .pb
格式。 Is there a way to do it?有没有办法做到这一点? I have taken the model from here我从这里拿了模型
The full code is available here .完整代码可在此处获得。
I have looked up here and it shows the following code to convert it:我查了一下here ,它显示了以下代码来转换它:
From tensorflow/models/research/
来自张量tensorflow/models/research/
INPUT_TYPE=image_tensor
PIPELINE_CONFIG_PATH={path to pipeline config file}
TRAINED_CKPT_PREFIX={path to model.ckpt}
EXPORT_DIR={path to folder that will be used for export}
python object_detection/export_inference_graph.py \
--input_type=${INPUT_TYPE} \
--pipeline_config_path=${PIPELINE_CONFIG_PATH} \
--trained_checkpoint_prefix=${TRAINED_CKPT_PREFIX} \
--output_directory=${EXPORT_DIR}
I am unable to figure out what value to pass:我无法弄清楚要传递什么值:
Here's the code to convert the checkpoint to SavedModel 这是将检查点转换为SavedModel的代码
import os
import tensorflow as tf
trained_checkpoint_prefix = 'models/model.ckpt-49491'
export_dir = os.path.join('export_dir', '0')
graph = tf.Graph()
with tf.compat.v1.Session(graph=graph) as sess:
# Restore from checkpoint
loader = tf.compat.v1.train.import_meta_graph(trained_checkpoint_prefix + '.meta')
loader.restore(sess, trained_checkpoint_prefix)
# Export checkpoint to SavedModel
builder = tf.compat.v1.saved_model.builder.SavedModelBuilder(export_dir)
builder.add_meta_graph_and_variables(sess,
[tf.saved_model.TRAINING, tf.saved_model.SERVING],
strip_default_attrs=True)
builder.save()
Following the answer of @Puneith Kaul, here is the syntax for tensorflow version 1.7: 在@Puneith Kaul回答之后,这是tensorflow 1.7版的语法:
import os
import tensorflow as tf
export_dir = 'export_dir'
trained_checkpoint_prefix = 'models/model.ckpt'
graph = tf.Graph()
loader = tf.train.import_meta_graph(trained_checkpoint_prefix + ".meta" )
sess = tf.Session()
loader.restore(sess,trained_checkpoint_prefix)
builder = tf.saved_model.builder.SavedModelBuilder(export_dir)
builder.add_meta_graph_and_variables(sess, [tf.saved_model.tag_constants.TRAINING, tf.saved_model.tag_constants.SERVING], strip_default_attrs=True)
builder.save()
If you specify INPUT_TYPE as image_tensor and PIPELINE_CONFIG_PATH as your config file with this command.如果您使用此命令将 INPUT_TYPE 指定为 image_tensor 并将 PIPELINE_CONFIG_PATH 指定为您的配置文件。
python object_detection/export_inference_graph.py \
--input_type=${INPUT_TYPE} \
--pipeline_config_path=${PIPELINE_CONFIG_PATH} \
--trained_checkpoint_prefix=${TRAINED_CKPT_PREFIX} \
--output_directory=${EXPORT_DIR}
you can get your model in 3 formats in your export dir;您可以在导出目录中以 3 种格式获取模型;
for more info https://github.com/tensorflow/models/tree/master/research/object_detection更多信息https://github.com/tensorflow/models/tree/master/research/object_detection
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.