Tensorflow Lite toco --mean_values --std_values?

女生的网名这么多〃 提交于 2019-12-12 09:19:12

问题


So I have trained a tensorflow model with fake quantization and froze it with a .pb file as output. Now I want to feed this .pb file to tensorflow lite toco for fully quantization and get the .tflite file.

I am using this tensorflow example: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro/examples/micro_speech

The part where I have question:

bazel run tensorflow/lite/toco:toco -- \
--input_file=/tmp/tiny_conv.pb --output_file=/tmp/tiny_conv.tflite \
--input_shapes=1,49,43,1 --input_arrays=Reshape_1 --output_arrays='labels_softmax' \
--inference_type=QUANTIZED_UINT8 --mean_values=0 --std_values=2 \
--change_concat_input_ranges=false

The above part calls toco and does the convert. Note that, the mean_values is set to 0, and std_values is set to 2 by Google. How did they calculate these 2 values? For this particular model, it is trained to recognize words "yes" and "no". What if I want to recognize the 10 digits, do I need to change the mean and std values in this case? I didn't find any official documentation illustrating this part. Any help would be appreciated.


回答1:


For uint8 quantized models the input values are expected to be in the range 0 to 255. Even with FakeQuantization, the input values during training are often float values in a different range (for example, 0.0 to 1.0). The mean_value and std_value controls how the uint8 values in the range 0 to 255 map to the float values used during training. You can use this heuristic to determine these values:

mean_value = the uint8 value in the range [0, 255] that corresponds to floating point 0.0. So if the float range is [0.0, 1.0], then mean_value = 0.

std_value = (uint8_max - uint8_min) / (float_max - float_min). So if the float range is [0.0, 1.0], then std_value = 255 / 1.0 = 255.

We are working on ways to make this simpler. Hope this helps!



来源:https://stackoverflow.com/questions/54261772/tensorflow-lite-toco-mean-values-std-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!