本工程用于二维码检测模型的浮点训练、面向平台的约束训练、量化训练、ONNX 导出、Thinker 打包和仿真验证。工程基于开源 YOLOv1 二维码检测示例修改,并针对 ListenAI VENUS、ARCS、VENUSA 平台做了适配。
支持平台:arcs、venus、venusa
原始工程参考:https://github.com/abeardear/pytorch-YOLO-v1/tree/master
对原工程做了适配:arcs、venus 使用平均池化,venusa 使用最大池化。
根据机器配置,参考 linger/thinker 官方教程配置环境,也可以直接使用对应 Docker 镜像。
示例环境仅供参考:Python 3.10、CUDA 11.8+、PyTorch、torchvision、linger、thinker 工具链。
conda create -n test_env python=3.10
conda activate test_env二维码数据集下载链接:
百度网盘: https://pan.baidu.com/s/1d66HKN-8773D2FmvyhMwFg
密码: 37rr
默认路径:
dataset/QRimages/:训练和测试图片目录dataset/train_labels-QRcode.txt:训练标注文件dataset/test_labels-QRcode.txt:测试标注文件
cd thinker/demo/QRcode_detection
# arcs
python train.py --type float --platform arcs --epochs 80 --out_path ./weights
# venus
python train.py --type float --platform venus --epochs 80 --out_path ./weights
#venusa
python train.py --type float --platform venusa --epochs 80 --out_path ./weights# arcs
python train.py --type clamp --platform arcs --epochs 20 --checkpoint ./weights/ori_weights/yolo-float-80-avgpool.pth --out_path ./weights
#venus
python train.py --type clamp --platform venus --epochs 20 --checkpoint ./weights/ori_weights/yolo-float-80-avgpool.pth --out_path ./weights
#venusa
python train.py --type clamp --platform venusa --epochs 20 --checkpoint ./weights/ori_weights/yolo-float-80-maxpool.pth --out_path ./weights#arcs
python train.py --type quant --platform arcs --epochs 20 --checkpoint ./weights/cweights/yolo-clamp-20-from-float80-arcs-avgpool.pth --out_path ./weights
#venus
python train.py --type quant --platform venus --epochs 20 --checkpoint ./weights/cweights/yolo-clamp-20-from-float80-venus-avgpool.pth --out_path ./weights
#venusa
python train.py --type quant --platform venusa --epochs 20 --checkpoint ./weights/cweights/yolo-clamp-20-from-float80-venusa-maxpool.pth --out_path ./weightscd thinker/demo/QRcode_detection
#arcs
tpacker -g ./weights/onnx_weights/yolo-quant-20-from-clamp20-avgpool-arcs.onnx -o ./weights/bin_pkg/model_arcs_40_5_5.bin --threshold1 32768 --threshold2 65536 --threshold4 32768 --dma_prefetch False
#venus
tpacker -g ./weights/onnx_weights/yolo-quant-20-from-clamp20-avgpool-venus.onnx -o ./weights/bin_pkg/model_venus_40_5_5.bin --threshold1 32768 --threshold2 65536 --threshold4 32768 --dma_prefetch False
#venusa
tpacker -g ./weights/onnx_weights/yolo-quant-5-from-clamp5-maxpool-venusa.onnx -o ./weights/bin_pkg/model_venusa_40_5_5.bin --threshold1 65536 --threshold2 65536 --threshold4 262100 --dma_prefetch=false在 thinker/CMakeLists.txt 中打开目标平台开关,例如 venus:
-DTHINKER_USE_VENUS=ON
-DTHINKER_USE_ARCS=OFF
-DTHINKER_USE_VENUSA=OFF
编译动态库:
cd thinker
sh ./scripts/x86_linux.sh执行仿真:
#arcs
./bin/test_thinker ./demo/QRcode_detection/weights/bin_pkg/model_arcs_40_5_5.bin ./demo/QRcode_detection/test/0000964.bin ./demo/QRcode_detection/test/output_arcs_40_5_5.bin
#venus
./bin/test_thinker ./demo/QRcode_detection/weights/bin_pkg/model_venus_40_5_5.bin ./demo/QRcode_detection/test/0000964.bin ./demo/QRcode_detection/test/output_venus_40_5_5.bin
#venusa
./bin/test_thinker ./demo/QRcode_detection/weights/bin_pkg/model_venusa_40_5_5.bin ./demo/QRcode_detection/test/0000964.bin ./demo/QRcode_detection/test/output_venusa_40_5_5.bincd thinker
# arcs
tvalidator -g ./demo/QRcode_detection/weights/onnx_weights/yolo-quant-20-from-clamp20-avgpool-arcs.onnx -r ./demo/QRcode_detection/weights/bin_pkg/model_arcs_40_5_5.bin
# venus
tvalidator -g ./demo/QRcode_detection/weights/onnx_weights/yolo-quant-20-from-clamp20-avgpool-venus.onnx -r ./demo/QRcode_detection/weights/bin_pkg/model_venus_40_5_5.bin
# venusa
tvalidator -g ./demo/QRcode_detection/weights/onnx_weights/yolo-quant-5-from-clamp5-maxpool-venusa.onnx -r ./demo/QRcode_detection/weights/bin_pkg/model_venusa_40_5_5.bin固件集成待补充。
modules/:模型结构定义criterion/:YOLO 损失函数prepare_data/:数据集读取逻辑configs/:不同平台的 linger 配置train.py:浮点、约束、量化训练入口;量化训练后自动导出 ONNXweights/:训练权重、ONNX、Thinker 打包结果test/:仿真输入输出样例docs/:示例图片和结果README.md:中文说明README_EN.md:英文说明