怎么把.ckpt转换成.pb? [英] How to convert .ckpt to .pb?

查看:329
本文介绍了怎么把.ckpt转换成.pb?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是深度学习的新手,我想使用预训练(EAST)模型从AI平台服务中进行服务,开发人员可以使用以下文件:

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:

  1. model.ckpt-49491.data-00000-of-00001
  2. 检查点
  3. model.ckpt-49491.index
  4. model.ckpt-49491.meta

我想将其转换为TensorFlow .pb格式.有办法吗?我从此处

I want to convert it into the TensorFlow .pb format. Is there a way to do it? I have taken the model from here

完整代码可在此处获得.

我在此处进行了查找并显示以下代码对其进行转换:

I have looked up here and it shows the following code to convert it:

来自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:

  • INPUT_TYPE
  • PIPELINE_CONFIG_PATH.

推荐答案

下面是将检查点转换为SavedModel的代码

Here's the code to convert the checkpoint to 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()                

这篇关于怎么把.ckpt转换成.pb?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆