尝试使用toco转换TF模型时出错

时间:2018-04-29 23:03:28

标签: python tensorflow tensorflow-lite

我有一个TF模型,我需要将其转换为int8,以便在嵌入式设备中实现。我试图使用toco转换它,但我无法确定如何正确地使用输入参数实例化toco:

<USER>:~/.local/bin$ python3 toco \
>   --input_file=<PATH>/frozen_graph.pb \
>   --output_file=<PATH>/tflite_graph.tflite \
>   --input_format=TENSORFLOW_GRAPHDEF \
>   --output_format=TFLITE \
>   --inference_type=QUANTIZED_UINT8 \
>   --output_arrays=Sidmoid \
>   --input_arrays=IteratorGetNext \
>   --input_shapes=1:16:16:1 \
>   --mean_values=128 \
>   --std_values=127
WARNING:tensorflow:From <USER>.local/lib/python3.5/site-packages/tensorflow/contrib/learn/python/learn/datasets/base.py:198: retry (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version.
Instructions for updating:
Use the retry module or similar alternatives.
2018-04-27 11:40:33.699249: F tensorflow/contrib/lite/toco/model_cmdline_flags.cc:240] Check failed: mean_values.size() == model_flags->input_arrays_size() 
Aborted (core dumped)

我了解mean_values输入arg存在问题,但我不明白其用途:

--mean_values="" string mean_values parameter for image models, comma-separated list of doubles, used to compute input activations from input pixel data. Each entry in the list should match an entry in --input_arrays.

我也尝试了",128,128,",因为我的解释是您不希望批量大小/通道变暗的平均值,但文档说它需要输入列表中的每个输入应该匹配input_arrays中的元素。

我也不确定要为input_arrays arg添加什么,因为我见过代码示例的大多数地方只使用input但是对我来说似乎你需要节点的名称图表。

我想我在这里误解了一些东西,但我似乎无法弄明白。任何帮助将不胜感激!

1 个答案:

答案 0 :(得分:0)

对于任何想知道的人来说,文档稍微让我感到困惑:它说“Input_shapes”是一串“形状对应于--input_arrays,冒号分隔......”但是尺寸仍然应该以逗号分隔:< / p>

bazel-bin/third_party/tensorflow/contrib/lite/toco/toco \
  --input_file=<my_path>/frozen_eval_graph.pb \
  --output_file=<my_path>/tflite_graph.tflite \
  --input_format=TENSORFLOW_GRAPHDEF \
  --output_format=TFLITE \
  --inference_type=QUANTIZED_UINT8 \
  --output_arrays=Sigmoid \
  --input_arrays=Reshape \
  --input_shapes=1,16,16,1 \
  --mean_values=128 \
  --std_values=127 \
  --variable_batch=true
相关问题