Tensorflow: Building graph and label files form checkpoint file

时间:2016-12-09 12:57:28

标签: android tensorflow deep-learning

I want to build the graph and labels file from inception-resnet-v2.ckpt file. I have already downloaded the check point file form wget http://download.tensorflow.org/models/inception_resnet_v2_2016_08_30.tar.gz.

I want to replace the inception5h model in tensorflow: android camera domo app with inception-resnet-v2. which requires a MODEL_FILE and a LABEL_FILE .

Now I don't know how I can get a .pb file and a label files from a checkpoint file. I am learning tensorflow, still at beginner level.

2 个答案:

答案 0 :(得分: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是图形定义(文本protobuf),快照是检查点。

答案 1 :(得分:0)

冻结后,您需要优化模型。

看看这个伟大的tutorial

对于标签,您可以获得hereHands-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