[英]Reducing .tflite model size
我看到的任何 zoo.tflite 模型的大小都不超过 3MB。 在 edgetpu 上,它们运行良好。 但是,当我训练自己的 object 检测 model 时,.pb 文件为 60MB,.tflite 也很大,为 20MB。 它也被量化如下。 最终结果是 edgetpu object_detection model 上的分段错误? 是什么导致这个文件这么大? 将未调整大小的图像输入 model 是否会导致 model 变大(某些照片为 4096×2160 且未调整大小)?
来自 object_detection
训练 model
python train.py \
--logtostderr \
--train_dir=training \
--pipeline_config_path=training/ssd_mobilenet_v1_coco.config
冻结图形- 创建 60MB.pb 文件
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 - 创建 20MB.tflite 文件
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 文件被推送到谷歌珊瑚 edgetpu,并且 model 在连接到 TPU 的 USB 相机上进行试验。
export DISPLAY=:0 && edgetpu_detect \
--source /dev/video1:YUY2:1280x720:20/1 \
--model ${DEMO_FILES}/detect.tflite
最终结果是分段错误。
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
这里的问题可能是由于每个步骤都有 2 个不同的配置文件:
python train.py \
...
--pipeline_config_path=training/ssd_mobilenet_v1_coco.config
python export_tflite_ssd_graph.py \
--pipeline_config_path=training/ssd_mobilenet_v2_coco.config \
...
这是故意的吗? 此外,看起来您在训练后立即部署了 model 而没有编译它。 有关 edgetpu_compiler 的更多信息,请参阅此文档: https://coral.withgoogle.com/docs/edgetpu/compiler/
AFAIK,只要满足页面上列出的所有要求,20MB model 应该可以正常运行:
您的整个管道应该是:
1) 训练 model
2) 转换为 tflite
3) 为 EdgeTPU 编译(实际上将工作委托给 TPU 的步骤)
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.