【问题标题】:Tensorflow: Building graph and label files form checkpoint fileTensorflow:构建图形和标签文件形成检查点文件
【发布时间】:2016-12-09 12:57:27
【问题描述】:

我想从 inception-resnet-v2.ckpt 文件构建图形和标签文件。我已经下载了检查点文件表格 wget http://download.tensorflow.org/models/inception_resnet_v2_2016_08_30.tar.gz.

我想用 inception-resnet-v2 替换 tensorflow: android camera domo 应用中的 inception5h 模型。这需要 MODEL_FILELABEL_FILE

现在我不知道如何从检查点文件中获取 .pb 文件和标签文件。 我正在学习 tensorflow,仍处于初级水平。

【问题讨论】:

    标签: android tensorflow deep-learning


    【解决方案1】:

    不确定标签文件是什么,但是要将检查点转换为 .pb 文件(即二进制 protobuf),您必须 freeze the graph。这是我使用的脚本:

    #!/bin/bash -x
    
    # The script combines graph definition and trained weights into
    # a single binary protobuf with constant holders for the weights.
    # The resulting graph is suitable for the processing with other tools.
    
    
    TF_HOME=~/tensorflow/
    
    if [ $# -lt 4 ]; then
        echo "Usage: $0 graph_def snapshot output_nodes output.pb"
        exit 0
    fi
    
    proto=$1
    snapshot=$2
    out_nodes=$3
    out=$4
    
    $TF_HOME/bazel-bin/tensorflow/python/tools/freeze_graph --input_graph=$proto \
        --input_checkpoint=$snapshot \
        --output_graph=$out \
        --output_node_names=$out_nodes 
    

    这里,proto 是一个 Graph 定义(文本 protobuf),snapshot 是一个检查点。

    【讨论】:

    • 感谢您回复@Dmytro。但这对我没有帮助。
    【解决方案2】:

    您需要在冻结模型后对其进行优化。

    看看这个很棒的tutorial

    您可以通过here 获取标签(感谢Hands-On Machine Learning with Scikit-Learn and TensorFlow

    bazel build tensorflow/python/tools:optimize_for_inference
    
    bazel-bin/tensorflow/python/tools/optimize_for_inference \
    --input=/tf_files/retrained_graph.pb \
    --output=/tf_files/optimized_graph.pb \
    --input_names=Mul \
    --output_names=final_result
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 2016-12-21
      相关资源
      最近更新 更多