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

Error when attempting to convert TF model using toco

我有一个 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,",因为我的解释是你不希望你的批处理 size/channel 暗淡的平均值,但文档说它需要每个输入的输入列表中的元素应匹配 input_arrays 中的元素。

我也不确定要为 input_arrays arg 添加什么,因为我看到代码示例的大多数地方都只使用 input 但对我来说,您似乎需要图中的节点。

我想我在这里误解了什么,但我似乎无法弄清楚。任何帮助将不胜感激!

对于任何想知道的人,是文档让我有点困惑:它说 "Input_shapes" 是一个 "Shapes corresponding to --input_arrays, colon separated..." 的字符串,但是尺寸仍然应该用逗号分隔:

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