paddle的版面分析的环境搭建及使用

一、什么是版面分析

版面分析技术,主要是对图片形式的文档进行版面分析,将文档划分为文字、标题、表格、图片以及列表5类区域,如下图所示:

二、应用场景

2.1 合同比对

2.2 文本类型划分

2.3 通用文档的还原

版面分析技术可将以word、pdf、图片等非结构化文档存储的信息还原为半结构化的电子数据,是非结构化文档信息利用首要任务。

三、paddle的版面分析

3.1 快速体验

参考网址链接

https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.7/ppstructure/docs/quickstart.md

环境搭建:

1)安装paddlepaddle

python3 -m pip install paddlepaddle-gpu -i https://mirror.baidu.com/pypi/simple【GPU版本】

python3 -m pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple【CPU版本】

2) 安装 paddleocr,推荐使用2.6版本

pip3 install "paddleocr>=2.6.0.3"

安装 图像方向分类依赖包paddleclas(如不需要图像方向分类功能,可跳过)

pip3 install paddleclas>=2.4.3

运行命令:

1)图像方向分类+版面分析+表格识别

paddleocr --image_dir=ppstructure/docs/table/1.png --type=structure --image_orientation=true

2) 版面分析+表格识别

paddleocr --image_dir=ppstructure/docs/table/1.png --type=structure

3)版面分析

paddleocr --image_dir=ppstructure/docs/table/1.png --type=structure --table=false --ocr=false

4)表格识别

复制代码
paddleocr --image_dir=ppstructure/docs/table/table.jpg --type=structure --layout=false

5)版面恢复(作用将PDF的文档转换成通用(word)文档)

仅仅处理pdf文档

paddleocr --image_dir=ppstructure/recovery/UnrealText.pdf --type=structure --recovery=true --use_pdf2docx_api=true

3.2 源码程序实现

  1. 安装PaddlePaddle

环境搭建

python3 -m pip install --upgrade pip

GPU安装

python3 -m pip install "paddlepaddle-gpu>=2.3" -i https://mirror.baidu.com/pypi/simple

CPU安装

python3 -m pip install "paddlepaddle>=2.3" -i https://mirror.baidu.com/pypi/simple

2)安装PaddleDetection

git clone https://github.com/PaddlePaddle/PaddleDetection.git

cd PaddleDetection

python3 -m pip install -r requirements.txt

需要自己训练数据集的,可以参考链接的攻略:

PaddleOCR/ppstructure/layout/README_ch.md at release/2.7 · PaddlePaddle/PaddleOCR · GitHub

预训练模型或者预测模型下载的官方网址为:

PaddleOCR/ppstructure/docs/models_list.md at release/2.7 · PaddlePaddle/PaddleOCR · GitHub

使用源码测试的命令,更换weights模型路径:

python 复制代码
python3 tools/infer.py \
    -c configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x1_0_layout.yml \
    --slim_config configs/picodet/legacy_model/application/layout_analysis/picodet_lcnet_x2_5_layout.yml \
    -o weights='output/picodet_lcnet_x2_5_layout/best_model.pdparams' \
    --infer_img='docs/images/layout.jpg' \
    --output_dir=output_dir/ \
    --draw_threshold=0.5

直接使用推理模型进行预测:

python 复制代码
python3 deploy/python/infer.py \
    --model_dir=output_inference/picodet_lcnet_x1_0_layout/ \
    --image_file=docs/images/layout.jpg \
    --device=GPU

备注:一些推理模型下载后,没有对应的yaml文件,会导致执行上面的指令出错,所以在运行上面的命令的时候,将下载的模型看看是否有对应的yaml文件。

相关推荐
CoovallyAIHub3 天前
仿生学突破:SILD模型如何让无人机在电力线迷宫中发现“隐形威胁”
深度学习·算法·计算机视觉
CoovallyAIHub3 天前
从春晚机器人到零样本革命:YOLO26-Pose姿态估计实战指南
深度学习·算法·计算机视觉
CoovallyAIHub3 天前
Le-DETR:省80%预训练数据,这个实时检测Transformer刷新SOTA|Georgia Tech & 北交大
深度学习·算法·计算机视觉
CoovallyAIHub3 天前
强化学习凭什么比监督学习更聪明?RL的“聪明”并非来自算法,而是因为它学会了“挑食”
深度学习·算法·计算机视觉
CoovallyAIHub3 天前
YOLO-IOD深度解析:打破实时增量目标检测的三重知识冲突
深度学习·算法·计算机视觉
这张生成的图像能检测吗5 天前
(论文速读)XLNet:语言理解的广义自回归预训练
人工智能·计算机视觉·nlp·注意力机制
十铭忘5 天前
自主认知-行动1——架构
人工智能·计算机视觉
yuzhuanhei5 天前
YOLO26实操记录(自用)
人工智能·计算机视觉·目标跟踪
sali-tec5 天前
C# 基于OpenCv的视觉工作流-章27-图像分割
图像处理·人工智能·opencv·算法·计算机视觉
音视频牛哥5 天前
Android平台RTMP/RTSP超低延迟直播播放器开发详解——基于SmartMediaKit深度实践
android·人工智能·计算机视觉·音视频·rtmp播放器·安卓rtmp播放器·rtmp直播播放器