使用TFLITE量化MobileFaceNet失败 [英] Quantize MobileFaceNet with TFLITE failed

查看:121
本文介绍了使用TFLITE量化MobileFaceNet失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试找到一种在AI相机上运行人脸识别的解决方案.并发现 MobileFacenet (

I am trying to find a solution to run face recognition on AI camera. And found that MobileFacenet (code from sirius-ai) is great as a light model!

我成功地以F32格式成功转换为TFLITE.但是,当我失败时,使用以下命令将其量化为uint8:

I succeed to convert to TFLITE with F32 format with good accuracy. However when I failed when quantized to uint8 with the following command:

tflite_convert --output_file tf-lite/MobileFacenet_uint8_128.tflite 
--graph_def_file tf-lite/MobileFacenet.pb 
--input_arrays "input" 
--input_shapes "1,112,112,3" 
--output_arrays output 
--output_format TFLITE 
--mean_values 128 
--std_dev_values 127.5 
--default_ranges_min 0 
--default_ranges_max 255 
--inference_type QUANTIZED_UINT8 
--inference_input_type QUANTIZED_UINT8

此线程有助于转换为TFLITE,但并未提及量化.有人可以提供一些建议吗?非常感谢!

This thread help to convert to TFLITE, but not talking about the quantization. Could anyone provide some suggestions? Many thanks!!

推荐答案

使用 tflite_convert 需要-saved_model_dir -keras_model_file 被定义.使用TF2.x时,如果要从冻结图转换为量化的tflite,则应使用-enable_v1_converter .

Using tflite_convert requires either --saved_model_dir or --keras_model_file to be defined. When using TF2.x, you should use --enable_v1_converter if you want to convert to quantized tflite from frozen graph.

您当前正在做的事情被称为虚拟量化",可以用来测试量化网络的推理时间.为了正确量化网络,应使用伪造的量化节点将层的最小/最大信息注入到网络中.

What you are currently doing is called "dummy quantization", which can be used to test the inference timings of the quantized network. To properly quantize the network, min/max information of layers should be injected into it with fake quant nodes.

请参见此要点,以获取有关如何执行此操作的示例代码.此博客文章还提供了一些有关量化意识训练的信息.

Please see this gist for example codes on how to do it. This blog post also has some information on quantization aware training.

这篇关于使用TFLITE量化MobileFaceNet失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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