Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何将.ckpt转换为.pb?_Python 3.x_Tensorflow_Google Cloud Platform_Google Cloud Ml - Fatal编程技术网

Python 3.x 如何将.ckpt转换为.pb?

Python 3.x 如何将.ckpt转换为.pb?,python-3.x,tensorflow,google-cloud-platform,google-cloud-ml,Python 3.x,Tensorflow,Google Cloud Platform,Google Cloud Ml,我是深度学习新手,我想使用预训练(EAST)模型从AI平台服务,我有开发人员提供的以下文件: 型号.ckpt-49491.data-00000-of-00001 检查站 model.ckpt-491.index model.ckpt-49491.meta 我想将其转换为TensorFlow.pb格式。有办法吗?我已经把模型从 完整代码可用 我查过了,它显示了以下转换代码: 来自tensorflow/models/research/ INPUT_TYPE=image_tensor PIPELINE

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

  • 型号.ckpt-49491.data-00000-of-00001
  • 检查站
  • model.ckpt-491.index
  • model.ckpt-49491.meta
  • 我想将其转换为TensorFlow
    .pb
    格式。有办法吗?我已经把模型从

    完整代码可用

    我查过了,它显示了以下转换代码:

    来自
    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}
    
    我无法计算要传递的值:

    • 输入类型
    • 管道配置路径

    以下是将检查点转换为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()                
    

    根据@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()
    

    如果将输入类型指定为图像张量,则 使用此命令将管道配置路径作为配置文件

    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}
    
    您可以在导出目录中获得3种格式的模型

    • 冻结图.pb
    • savedmodel.pb
    • 检查站

    有关更多信息

    您需要SavedModel格式,请确保先将其转换为此格式,然后可以使用saved_model_cli工具分析您的模型。请详细说明。我该怎么做呢。或者请给我推荐一些阅读材料。非常感谢你的帮助。我成功地转换了模型,但无法部署它,因为它的大小超过了给定的大小。如何缩小我的模型。你可以试试Nvidia TensorRT工具,看看这篇文章:有没有类似于物体识别的东西?我正在使用此网页:
    https://github.com/tensorflow/models/tree/master/research/slim#exporting-推理图
    ,但我无法转换为。PB在没有“.meta”的情况下,有没有办法对对象识别进行同样的操作?我正在使用此网页:
    https://github.com/tensorflow/models/tree/master/research/slim#exporting-推理图
    ,但我无法将.ckpt模型转换为.pb