Tensorflow Lite toco --mean_values --std_values? [英] Tensorflow Lite toco --mean_values --std_values?

查看:42
本文介绍了Tensorflow Lite toco --mean_values --std_values?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我用假量化训练了一个 tensorflow 模型,并用 .pb 文件作为输出将其冻结.现在我想将此 .pb 文件提供给 tensorflow lite toco 以进行完全量化并获取 .tflite 文件.

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.

我正在使用这个 tensorflow 示例:https://github.com/tensorflow/tensorflow/tree/master/tensorflow/lite/experimental/micro/examples/micro_speech

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

我有疑问的部分:

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

以上部分调用 toco 并进行转换.请注意,Google 将 mean_values 设置为 0,std_values 设置为 2.他们是如何计算这两个值的?对于这个特定的模型,它被训练来识别单词是"和否".如果我想识别 10 位数字,在这种情况下是否需要更改均值和标准值?我没有找到任何说明这部分的官方文档.任何帮助,将不胜感激.

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.

推荐答案

对于 uint8 量化模型,输入值预计在 0 到 255 的范围内.即使使用 FakeQuantization,训练期间的输入值通常是浮点值不同的范围(例如,0.0 到 1.0).mean_value 和 std_value 控制 0 到 255 范围内的 uint8 值如何映射到训练期间使用的浮点值.您可以使用此启发式方法来确定这些值:

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 = [0, 255] 范围内对应于浮点 0.0 的 uint8 值.所以如果浮动范围是[0.0, 1.0],那么mean_value = 0.

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).所以如果浮动范围是 [0.0, 1.0],那么 std_value = 255/1.0 = 255.

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!

这篇关于Tensorflow Lite toco --mean_values --std_values?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆