gpt4 book ai didi

python - 减小 TFLite 模型大小?

转载 作者:行者123 更新时间:2023-11-28 18:09:38 27 4
gpt4 key购买 nike

我目前正在按照本指南制作多标签图像分类模型(它使用初始模型作为基础模型):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

所以,我有几个问题:

  1. 将模型转换为 .tflite 后,我预计尺寸会减少多少?
  2. 是否有任何方法可以在减小尺寸的同时仍然能够转换为适合移动设备的模型?如果没有,我猜我需要转换 mobilenet 以使用多标签分类。

最佳答案

好的,所以我找到了一种方法来做到这一点。我使用优化图(未量化)并运行以下命令:

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 android 代码,以允许我使用量化的 tflite 图(基本上与此相反 - https://github.com/tensorflow/tensorflow/issues/14719),而且我得到的结果似乎与原始结果一样好,未量化图。

关于python - 减小 TFLite 模型大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51502539/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com