我正在按照本指南(它使用初始作为基本模型)制作多标签图像分类模型:https://towardsdatascience.com/multi-label-image-classification-with-inception-net-cbb2ee538e30
从.pb
转换为.tflite
后,该模型仅减少约0.3mb。
这是我的转换代码:
toco \
--graph_def_file=optimized_graph.pb \
--output_file=output/optimized_graph.tflite \
--output_format=TFLITE \
--input_shape=1,299,299,3 \
--input_array=Mul \
--output_array=final_result \
--inference_type=FLOAT \
--inference_input_type=FLOAT
所以,我有几个问题:
好的,所以我找到了办法。我使用优化图(未量化)并运行以下命令:
tflite_convert --graph_def_file=optimized_graph.pb \
--output_file=output/optimized_graph_quantized.tflite \
--output_format=TFLITE \
--input_shape=1,299,299,3 \
--input_array=Mul \
--output_array=final_result \
--inference_type=QUANTIZED_UINT8 \
--std_dev_values=128 --mean_values=128 \
--default_ranges_min=-6 --default_ranges_max=6 \
--quantize_weights=true
我主要关心的是,当我没有指定最小/最大范围时,我得到以下消息:“数组转换,它是产生输出数组conv_1的Conv运算符的输入,缺少最小/最大数据,量化是必要的。要么定位非量化的输出格式,要么改变输入图形以包含最小/最大信息,或者如果你不关心结果的准确性,则传递--default_ranges_min =和--default_ranges_max =。
我已经改变了tf-for-poets安卓代码,允许我使用量化的tflite图形(基本上与此相反 - https://github.com/tensorflow/tensorflow/issues/14719),我似乎得到的结果与原始的,未量化的图形一样好。
我使用@ChristopherPaterson解决方案解决了同样的问题,但删除--quantize_weights=true
为我工作。命令是:
tflite_convert --graph_def_file=optimized_graph.pb \
--output_file=output/optimized_graph_quantized.tflite \
--output_format=TFLITE \
--input_shape=1,299,299,3 \
--input_array=Mul \
--output_array=final_result \
--inference_type=QUANTIZED_UINT8 \
--std_dev_values=128 --mean_values=128 \
--default_ranges_min=-6 --default_ranges_max=6