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

标签 python-3.x tensorflow google-cloud-platform google-cloud-ml

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

  • model.ckpt-49491.data-00000-of-00001
  • 检查站
  • model.ckpt-49491.index
  • model.ckpt-49491.meta

  • 我想把它转换成 TensorFlow .pb格式。有没有办法做到这一点?我的模型来自 here

    完整代码可用here .

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

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

    我无法弄清楚要传递什么值:
  • INPUT_TYPE
  • PIPELINE_CONFIG_PATH。
  • 最佳答案

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

    关于python-3.x - 如何将 .ckpt 转换为 .pb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56766639/

    相关文章:

    google-cloud-platform - 高效的 Google PubSub 发布

    firebase - 使用 onSnapshot firestore 时需要支付多少钱?

    python - 使用列表内的列表时如何处理 KeyError

    python - 在Python中解压字典列表

    linux - 是否有可能在 Windows Linux 子系统上获得 OpenCL?

    python - 使用 LSTM ptb 模型 tensorflow 示例预测下一个词

    python - tensorflow/models.. 在 Windows 中的位置

    python - 在 python 中滚动前 3 个月的唯一总和

    python-3.x - 从 __main__ 保存列表

    google-cloud-platform - 为什么我们需要在 GCP 中使用 Cloud Scheduler 发布/订阅?