我按照教程(https://www.tensorflow.org/performance/quantization)生成量化的graphdef文件:
curl -L "https://storage.googleapis.com/download.tensorflow.org/models/inception_v3_2016_08_28_frozen.pb.tar.gz" | tar -C tensorflow/examples/label_image/data -xz
bazel build tensorflow/tools/graph_transforms:transform_graph
bazel-bin/tensorflow/tools/graph_transforms/transform_graph \
--in_graph=tensorflow/examples/label_image/data/inception_v3_2016_08_28_frozen.pb \
--out_graph=/tmp/inception_v3_quantized_graph.pb \
--inputs=input \
--outputs=InceptionV3/Predictions/Reshape_1 \
--transforms='add_default_attributes strip_unused_nodes(type=float, shape="1,299,299,3")
remove_nodes(op=Identity, op=CheckNumerics) fold_constants(ignore_errors=true)
fold_batch_norms fold_old_batch_norms quantize_weights quantize_nodes
strip_unused_nodes sort_by_execution_order'
然后将量化后的graphdef转换为tflite文件:
bazel-bin/tensorflow/contrib/lite/toco/toco \
--input_file=/tmp/inception_v3_quantized_graph.pb\
--output_file=/tmp/inception_v3_quantized_graph.lite \
--input_format=TENSORFLOW_GRAPHDEF \
--output_format=TFLITE \
--inference_type=QUANTIZED_UINT8 --input_type=QUANTIZED_UINT8\
--input_shape=1,299,299,3 \
--input_array=input \
--output_array=InceptionV3/Predictions/Reshape_1 \
--mean_value=128 \
--std_value=127
它失败并出现以下错误:
2017-11-23 12:36:40.637143: F tensorflow/contrib/lite/toco/tooling_util.cc:549] Check failed: model.arrays.count(input_array.name()) Input array not found: input
Aborted (core dumped)
运行 summarise_graph 工具
bazel-bin/tensorflow/tools/graph_transforms/summarize_graph \
--in_graph=/tmp/inception_v3_quantized_graph.pb
输入节点存在。
Found 1 possible inputs: (name=input, type=float(1), shape=[1,299,299,3])
No variables spotted.
Found 1 possible outputs: (name=InceptionV3/Predictions/Reshape_1,
op=Dequantize)
Found 23824934 (23.82M) const parameters, 0 (0) variable parameters, and 268
control_edges
Op types used: 673 Const, 214 Requantize, 214 RequantizationRange, 134 Reshape, 134 Max, 134 Min, 134 QuantizeV2, 95 QuantizedConv2D, 94 QuantizedRelu, 94 QuantizedAdd, 49 Dequantize, 24 QuantizedMul, 15 ConcatV2, 10 QuantizedAvgPool, 4 QuantizedMaxPool, 2 QuantizedReshape, 1 QuantizedBiasAdd, 1 Placeholder, 1 Softmax, 1 Squeeze
我错过了什么吗?将量化的graphdef文件转换为tflite文件的正确方法是什么?
谢谢!