首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >减小.tflite模型尺寸

减小.tflite模型尺寸
EN

Stack Overflow用户
提问于 2019-10-25 15:40:26
回答 1查看 1.5K关注 0票数 1

我看到的动物园.tflite型号的大小都不超过3MB。他们跑得很好。但是,当我训练我自己的对象检测模型时,.pb文件是60 my,.tflite也是20 my。它也是量化的如下所示。最终的结果是在edgetpu object_detection模型上分割错误。是什么导致这个文件这么大?非调整大小的图像被输入到模型中是否会导致模型很大(有些照片是4096×2160而不是调整大小)?

来自object_detection

训练模型

代码语言:javascript
复制
python train.py \
--logtostderr \
--train_dir=training \
--pipeline_config_path=training/ssd_mobilenet_v1_coco.config

冻结图形-创建60 .pb的.pb文件

代码语言:javascript
复制
python export_tflite_ssd_graph.py \
--pipeline_config_path=training/ssd_mobilenet_v2_coco.config \
--trained_checkpoint_prefix=training/model.ckpt-2020 \
--output_directory=inference_graph \
--add_postprocessing_op=true 

转换为.tflite -创建20 to的.tflite文件

代码语言:javascript
复制
tflite_convert 
--graph_def_file=inference_graph/tflite_graph.pb \
--output_file=inference_graph/detect.tflite \
--inference_type=QUANTIZED_UINT8 \
--input_shapes=1,300,300,3 \
--input_arrays=normalized_input_image_tensor \
--output_arrays=TFLite_Detection_PostProcess,TFLite_Detection_PostProcess:1,TFLite_Detection_PostProcess:2,TFLite_Detection_PostProcess:3 \
--mean_values=128 \
--std_dev_values=127 \
--allow_custom_ops \
--default_ranges_min=0 \
--default_ranges_max=6

在这个阶段,.tflite文件被推送到,并在连接到TPU的USB摄像头上试用该模型。

代码语言:javascript
复制
export DISPLAY=:0 && edgetpu_detect \
--source /dev/video1:YUY2:1280x720:20/1  \
--model ${DEMO_FILES}/detect.tflite

最终结果是分割错误。

代码语言:javascript
复制
INFO: Initialized TensorFlow Lite runtime.
glvideomixer name=mixer background=black ! glimagesink sync=False name=glsink qos=False
v4l2src device=/dev/video1 ! video/x-raw,height=720,framerate=20/1,format=YUY2,width=1280 ! glupload ! tee name=t
t. ! glupload ! queue ! mixer.
overlaysrc name=overlay ! video/x-raw,height=720,width=1280,format=BGRA ! glupload ! queue max-size-buffers=1 ! mixer.
t. ! queue max-size-buffers=1 leaky=downstream ! glfilterbin filter=glcolorscale ! video/x-raw,height=168,width=300,format=RGBA ! videoconvert ! video/x-raw,height=168,width=300,format=RGB ! videobox autocrop=True ! video/x-raw,height=300,width=300 ! appsink max-buffers=1 sync=False emit-signals=True drop=True name=appsink
Segmentation fault
EN

回答 1

Stack Overflow用户

发布于 2019-10-29 15:48:14

这里的问题可能是由于每个步骤都有两个不同的配置文件:

代码语言:javascript
复制
python train.py \
...
--pipeline_config_path=training/ssd_mobilenet_v1_coco.config
代码语言:javascript
复制
python export_tflite_ssd_graph.py \
--pipeline_config_path=training/ssd_mobilenet_v2_coco.config \
...

这是注定的吗?而且,看起来在没有编译的情况下,您在培训后立即部署了模型。有关edgetpu_compiler:https://coral.withgoogle.com/docs/edgetpu/compiler/的更多信息,请参阅此文档

AFAIK,只要满足页面上列出的所有要求,20 on的型号就应该运行得很好:

(8位定点numbers).

  • Tensor尺寸在编译时为常数(无动态尺寸),

  • 模型参数(如偏置张量)在compile-time.

  • Tensors处为常数,为1-、2-或3维.如果一个张量大于3维,那么只有最里面的3个维度的尺寸可能大于1。

你的整个管道应该是:

1)模型的训练

2)转换为tflite

3)为EdgeTPU编译的(实际将工作委托给TPU的步骤)

希望这能有所帮助。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58561680

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档