Tensorflow Lite:如何检查input_layer_shape和input_layer_type以将pb转换为tflite

时间:2018-09-06 09:24:35

标签: python-3.x tensorflow tensorflow-lite toco

如何填写正确的参数以转换tflite?

以下是失败的消息和pb信息,

(1)失败的消息

~/tensorflow/pkg/tensorflow$ bazel-bin/tensorflow/contrib/lite/toco/toco \
--input_format=TENSORFLOW_GRAPHDEF \
--input_file='retrained_graph.pb' \
--output_format=TFLITE \
--output_file='retrained_graph.tflite' \
--inference_type=FLOAT \
--inference_input_type=FLOAT \
--output_arrays=final_result \
--input_arrays=batch_size,phase_train \
--input_shapes=1,160,160,3:False \
--mean_values=128 \
--std_values=128
2018-09-06 17:16:14.249938: F tensorflow/contrib/lite/toco/model_cmdline_flags.cc:263] Check failed: mean_values.size() == model_flags->input_arrays_size()

(2)铅信息

xxxx:~/tensorflow/pkg/tensorflow$ bazel-bin/tensorflow/tools/graph_transforms/summarize_graph --in_graph='zzz/retrained_graph.pb'
Found 2 possible inputs: (name=batch_size, type=int32(3), shape=<unknown>) (name=phase_train, type=bool(10), shape=<unknown>) 
No variables spotted.
Found 1 possible outputs: (name=final_result, op=Softmax) 
Found 23514555 (23.51M) const parameters, 0 (0) variable parameters, and 675 control_edges
Op types used: 2019 Switch, 1104 Const, 1057 Identity, 449 Sub, 449 Merge, 247 Mul, 224 FusedBatchNorm, 132 Conv2D, 131 Relu, 24 Add, 23 ConcatV2, 21 BiasAdd, 3 MaxPool, 3 Shape, 3 Reshape, 2 MatMul, 2 Placeholder, 1 PlaceholderWithDefault, 1 AvgPool, 1 StridedSlice, 1 Softmax, 1 RealDiv, 1 RandomUniform, 1 QueueDequeueUpToV2, 1 FIFOQueueV2, 1 Pack, 1 Floor
To use with tensorflow/tools/benchmark:benchmark_model try these arguments:
bazel run tensorflow/tools/benchmark:benchmark_model -- --graph=zzz/retrained_graph.pb --show_flops --input_layer=batch_size,phase_train --input_layer_type=int32,bool --input_layer_shape=: --output_layer=final_result

1 个答案:

答案 0 :(得分:1)

如果您不对模型使用量化,则可以完全跳过--mean_values--std_values输入参数。

仅当使用量化(--inference_type=QUANTIZED_UINT8)时才需要这些标志。如果您确实使用了量化并指定了meanstd,则需要为每个输入(在这种情况下,batch_sizephase_train都这样做)。 / p>