Hi3516DV500部署paddle版型分析模型记录

原版模型测试并导出onnx

paddle 版面分析->

https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.7/ppstructure/layout/README_ch.md

测试

python3 deploy/python/infer.py \

--model_dir=model/picodet_lcnet_x1_0_fgd_layout_cdla_infer/ \

--image_file=image/test.jpg \

--device=CPU

测试结果

修改模型输入为960*960

使用该工具https://github.com/jiangjiajun/PaddleUtils/tree/main/paddle

python paddle_infer_shape.py --model_dir paddle_model/picodet_lcnet_x1_0_fgd_layout_cdla_infer \

--model_filename model.pdmodel \

--params_filename model.pdiparams \

--save_dir ./new_model \

--input_shape_dict="{'image':[1,3,960,960]}"

导出为onnx model

paddle2onnx --model_dir model/picodet_lcnet_x1_0_fgd_layout_cdla_infer \

--model_filename model.pdmodel \

--params_filename model.pdiparams \

--opset_version 11 \

--input_shape_dict="{'image':[1, 3, 960, 960]}" \

--save_file ./onnx_model/pico_det_lcnet_960.onnx

onnx推理

python deploy/third_engine/onnx/infer.py \

--infer_cfg model/picodet_lcnet_x1_0_fgd_layout_cdla_infer/infer_cfg.yml \

--onnx_file onnx_model/pico_det_lcnet.onnx \

--image_file image/test.jpg

Version:0.9 StartHTML:0000000105 EndHTML:0000036175 StartFragment:0000000141 EndFragment:0000036139

c++推理

https://github.com/PaddlePaddle/PaddleDetection/blob/release/2.6/deploy/cpp/docs/linux_build.md

./build/ppocr --layout_model_dir=inference/layout/ \

--image_dir=../../ppstructure/docs/table/DBnet_test.jpg \

--type=structure --table=false --layout=true --det=false --rec=false

板端部署

模型转换onnx->om

1:准备pico_det的onnx模型--->

搭建好ATC的环境--> 海思SS928搭建NNN环境-CSDN博客

首先设置环境变量

source /home/warren/Ascend/ascend-toolkit/latest/x86_64-linux/bin/setenv.bash

转化模型

量化

atc --model=/home/wzw/00-Ascend/model/pico_det_lcnet/pico_det_lcnet.onnx \

--framework=5 \

--output=/home/wzw/00-Ascend/model/pico_det_lcnet/pico_det_lcnet_quat\

--image_list="image:./image_data.bin" --input_type="image:FP32"

不量化

atc --model=/home/wzw/00-Ascend/model/pico_det_lcnet/pico_det_lcnet.onnx \

--framework=5 \

--output=/home/wzw/00-Ascend/model/pico_det_lcnet/00-result/pico_det_lcnet \

--image_list="image:./image_data.bin" --input_type="image:FP32" \ --net_optimize_enable=0 --layer_fusion_enable=0 --layer_m2m_enable=0

推理代码编写

安装opencv库 Hi3516DV500 SVP_NNN添加opencv库记录-CSDN博客

部署框架代码逻辑

mkdir -p build/intermediates/soc

cd build/intermediates/soc

cmake ../../../src -Dtarget=board -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_COMPILER=aarch64-v01c01-linux-gnu-gcc

make

原版模型测试结果

由此可见原始模型对于论文的识别准确度较高,但是对于报纸和杂志的识别并不精确,因此我们需要对其进行重新训练

重新训练模型

参考 https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.7/ppstructure/layout/README_ch.md

默认使用的是PubLayNet数据集,但我们需要使用CLDA

首先准备好数据集 https://github.com/buptlihang/CDLA

因为该数据集的标注格式是labelme,但是训练现需要的是coco格式,使用该项目中的labelme2coco.py进行格式转换,

python3 labelme2coco.py ./train/ train_self --labels labels.txt

python3 labelme2coco.py ./val val_self --labels labels.txt

错误一

但是这里的label text有12个类,这样会导致超出索引的错误导致训练失败,因此我们需要改一下labels.txt;

但是直接更改会报如下错误错

解决办法注释即可


训练

参照 https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.7/ppstructure/layout/README_ch.md

首先复制一份

configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout.yml

改名为picodet_lcnet_x1_0_layout_self.yml

num_class 改为10,更改红框的信息,这里需要注意的是imagedir的位置,batchzsize也需要调小,不然会导致内存溢出

内寸溢出,需要调整一下batch size

减小学习率

同时注意下版本

直接训练会有很多错误

下图错误就是label.txt的个数没有改为10个

未匹配到coco数据集下载链接

解决办法注释如下代码

修改完成后训练成功

python3 tools/train.py \

-c configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout_self.yml --eval

自己准备的数据集只需要按照coco格式调整即可;

测试生成的模型

python3 tools/infer.py \

-c configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout_self.yml \

--slim_config configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x2_5_layout.yml \

-o weights='output/picodet_lcnet_x1_0_layout_self/best_model.pdparams' \

--infer_dir='dataset/CDLA/val_self/image' --output_dir=output_dir/ --draw_threshold=0.4

导出模型

这里需要注意加上export.benchmark=True export.nms=False!!!不要加入后处理和nms

python3 tools/export_model.py \

-c configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout_self.yml \

--slim_config configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x2_5_layout.yml \

-o weights=./output/picodet_lcnet_x1_0_layout_self/best_model export.benchmark=True export.nms=False \

--output_dir=output_inference/

导出模型推理

python3 deploy/python/infer.py \

--model_dir=output_inference/picodet_lcnet_x1_0_layout_self/ \

--image_file=./image/DBnet_test.jpg \

--device=GPU

可以看到准确度已经有很大的提升了,重新部署到板端

重新训练后板端的的测试结果

可以看到准确度提升很多;

相关推荐
媒体人88816 小时前
GEO优化专家孟庆涛谈 GEO 优化:百度抖音谷歌协同抢答案主权
大数据·人工智能·搜索引擎·生成式引擎优化·geo优化
Tandy12356_16 小时前
手写TCP/IP协议栈——数据包结构定义
c语言·网络·c++·计算机网络
智元视界16 小时前
智慧金融智能风控:AI算法如何服务小微企业
人工智能·金融·架构·云计算·数字化转型·产业升级
东南门吹雪16 小时前
向量、张量、大语言模型、Embedding
人工智能·语言模型·embedding
繁华似锦respect16 小时前
HTTPS 中 TLS 协议详细过程 + 数字证书/签名深度解析
开发语言·c++·网络协议·http·单例模式·设计模式·https
qq_3561969516 小时前
day27pipeline管道@浙大疏锦行
python
桃子叔叔16 小时前
Prompt Engineering 完全指南:从基础到高阶技术深度解析
大数据·人工智能·prompt
腾飞开源16 小时前
14_Spring AI 干货笔记之 Azure OpenAI 对话模型
人工智能·向量存储·对话模型·工具调用·spring ai·azure openai·ai模型集成
噔噔噔噔@16 小时前
第一章、基础理论——第一节、软件测试概述
python·单元测试·压力测试
晨同学032716 小时前
【中文】CLIP4Clip: An Empirical Study of CLIP for End to End Video Clip Retrieval
人工智能·多模态