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

问题描述 投票:1回答:1

如何填写转换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)PB信息

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
python-3.x tensorflow tensorflow-lite toco
1个回答
1
投票

如果你没有在模型中使用量化,你可以完全跳过--mean_values--std_values输入args。

只有在使用量化(--inference_type=QUANTIZED_UINT8)时才需要这些标志。如果使用量化并指定meanstd,则需要为每个输入执行此操作(在本例中,batch_sizephase_train)。

© www.soinside.com 2019 - 2024. All rights reserved.