PaddleOCR表格识别运行实例

目录

PaddleOCR 开源项目地址

一、数据集

1. 训练数据下载

2.数据集介绍

 (1)PubTabNet数据集

(2) 好未来表格识别竞赛数据集

(3)WTW中文场景表格数据集

二、训练步骤

1.数据放置

2.环境配置

(1)PaddlePaddle框架安装

    第一步:查看计算机平台版本

   第二步、根据以下条件进行选择自动生成安装命令

(2)其他环境包安装

3.训练参数设置

4.启动训练

5.推理过程

三、踩坑记录


PaddleOCR 开源项目地址

PaddlePaddle/PaddleOCR: Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices) (github.com)

一、数据集

1. 训练数据下载

PaddleOCR/doc/doc_ch/dataset/table_datasets.md at c27402bf1f012aeb54a98eb12ba98883eded502e · PaddlePaddle/PaddleOCR · GitHub

 

2.数据集介绍

 (1)PubTabNet数据集

 训练集合中包含50万张图像,验证集合中包含0.9万张图像 :https://github.com/ibm-aur-nlp/PubTabNet

(此次训练以 PubTabNet数据集为例) 

             

数据格式如下所示:

{
   'filename': PMC5755158_010_01.png,                            # 图像名
   'split': ’train‘,                                     # 图像属于训练集还是验证集
   'imgid': 0,                                         # 图像的index
   'html': {
     'structure': {'tokens': ['<thead>', '<tr>', '<td>', ...]},             # 表格的HTML字符串
     'cells': [
       {
         'tokens': ['P', 'a', 'd', 'd', 'l', 'e', 'P', 'a', 'd', 'd', 'l', 'e'],     # 表格中的单个文本
         'bbox': [x0, y0, x1, y1]                              # 表格中的单个文本的坐标
       }
     ]
   }
}

备注:PubTabNet_2.0.0.jsonl里面的label信息未将训练、验证数据集分开,如果有需要可以写脚本将其分开,或者训练过程中直接忽略掉读取错误的路径(图片读取文PaddleOCR-release-2.7/ppocr/data/pubtab_dataset.py)。

(2) 好未来表格识别竞赛数据集

识别竞赛数据集的训练集合中包含1.6万张图像。验证集未给出可训练的标注:https://ai.100tal.com/dataset

(3)WTW中文场景表格数据集

包含表格检测和表格数据两部分数据,数据集中同时包含扫描和拍照两张场景的图像:GitHub - wangwen-whu/WTW-Dataset: This is an official implementation for the WTW Dataset in "Parsing Table Structures in the Wild " on table detection and table structure recognition.

二、训练步骤

1.数据放置

PaddleOCR-release-2.7/train_data/table/ 路径下(默认,可更改)

如果您的磁盘上已有数据集,只需创建软链接至数据集目录:

# linux and mac os
ln -sf <path/to/dataset> <path/to/paddle_ocr>/train_data/dataset
# windows
mklink /d <path/to/paddle_ocr>/train_data/dataset <path/to/dataset>

2.环境配置

 提示:可在python环境中进行安装,避免环境污染,创建命令conda create -n xxx_name python=3.9,激活conda activate xxx_name

(1)PaddlePaddle框架安装
    第一步:查看计算机平台版本

   在窗口输入查看命令,查看CUDA的版本

nvidia-smi

      第二步、根据以下条件进行选择自动生成安装命令

快速安装路径:飞桨PaddlePaddle-源于产业实践的开源深度学习平台

(2)其他环境包安装

使用如下命令一键配置:

pip install -r requirements.txt

3.训练参数设置

打开:PaddleOCR-release-2.7\configs\table\SLANet.yml

Global:
  use_gpu: True     #GPU是否使用
  epoch_num: 100    #训练轮次
  log_smooth_window: 20
  print_batch_step: 20
  save_model_dir: ./output/SLANet
  save_epoch_step: 400
  # evaluation is run every 1000 iterations after the 0th iteration
  eval_batch_step: [0, 1000]
  cal_metric_during_train: True
  pretrained_model:
  checkpoints:
  save_inference_dir: ./output/SLANet/infer  #保存路径
  use_visualdl: False
  infer_img: ppstructure/docs/table/table.jpg
  # for data or label process
  character_dict_path: ppocr/utils/dict/table_structure_dict.txt
  character_type: en
  max_text_length: &max_text_length 500
  box_format: &box_format 'xyxy' # 'xywh', 'xyxy', 'xyxyxyxy'
  infer_mode: False
  use_sync_bn: True
  save_res_path: 'output/infer'
  d2s_train_image_shape: [3, -1, -1]
  amp_custom_white_list: ['concat', 'elementwise_sub', 'set_value']

Optimizer:
  name: Adam
  beta1: 0.9
  beta2: 0.999
  clip_norm: 5.0
  lr:
    name: Piecewise
    learning_rate: 0.001
    decay_epochs : [40, 50]
    values : [0.001, 0.0001, 0.00005]
  regularizer:
    name: 'L2'
    factor: 0.00000

Architecture:
  model_type: table
  algorithm: SLANet
  Backbone:
    name: PPLCNet
    scale: 1.0
    pretrained: true
    use_ssld: true
  Neck:
    name: CSPPAN
    out_channels: 96
  Head:
    name: SLAHead
    hidden_size: 256
    max_text_length: *max_text_length
    loc_reg_num: &loc_reg_num 4

Loss:
  name: SLALoss
  structure_weight: 1.0
  loc_weight: 2.0
  loc_loss: smooth_l1

PostProcess:
  name: TableLabelDecode
  merge_no_span_structure: &merge_no_span_structure True

Metric:
  name: TableMetric
  main_indicator: acc
  compute_bbox_metric: False
  loc_reg_num: *loc_reg_num
  box_format: *box_format

Train:
  dataset:
    name: PubTabDataSet
    data_dir: train_data/table/pubtabnet/train/   #训练集路径
    label_file_list: [train_data/table/pubtabnet/PubTabNet_2.0.0.jsonl]  #标签文件路径
    transforms:
      - DecodeImage: # load image
          img_mode: BGR
          channel_first: False
      - TableLabelEncode:
          learn_empty_box: False
          merge_no_span_structure: *merge_no_span_structure
          replace_empty_cell_token: False
          loc_reg_num: *loc_reg_num
          max_text_length: *max_text_length
      - TableBoxEncode:
          in_box_format: *box_format
          out_box_format: *box_format
      - ResizeTableImage:
          max_len: 488
      - NormalizeImage:
          scale: 1./255.
          mean: [0.485, 0.456, 0.406]
          std: [0.229, 0.224, 0.225]
          order: 'hwc'
      - PaddingTableImage:
          size: [488, 488]
      - ToCHWImage:
      - KeepKeys:
          keep_keys: [ 'image', 'structure', 'bboxes', 'bbox_masks', 'shape' ]
  loader:
    shuffle: True
    batch_size_per_card: 16      # batch_size大小设置
    drop_last: True
    num_workers: 1

Eval:
  dataset:
    name: PubTabDataSet
    data_dir: train_data/table/pubtabnet/val/     #训练集路径
    label_file_list: [train_data/table/pubtabnet/PubTabNet_2.0.0.jsonl]  #训练集路径标签文件路径
    transforms:
      - DecodeImage: # load image
          img_mode: BGR
          channel_first: False
      - TableLabelEncode:
          learn_empty_box: False
          merge_no_span_structure: *merge_no_span_structure
          replace_empty_cell_token: False
          loc_reg_num: *loc_reg_num
          max_text_length: *max_text_length
      - TableBoxEncode:
          in_box_format: *box_format
          out_box_format: *box_format
      - ResizeTableImage:
          max_len: 488
      - NormalizeImage:
          scale: 1./255.
          mean: [0.485, 0.456, 0.406]
          std: [0.229, 0.224, 0.225]
          order: 'hwc'
      - PaddingTableImage:
          size: [488, 488]
      - ToCHWImage:
      - KeepKeys:
          keep_keys: [ 'image', 'structure', 'bboxes', 'bbox_masks', 'shape' ]
  loader:
    shuffle: False
    drop_last: False
    batch_size_per_card: 16     # batch_size大小设置
    num_workers: 1

4.启动训练

#多卡训练,通过--gpus参数指定卡号
python3 -m paddle.distributed.launch --gpus '0,1,2,3'  tools/train.py -c configs/table/SLANet.yml

服务器界面显示结果

5.推理过程

# 预测表格图像
python3 tools/infer_table.py -c configs/table/SLANet.yml -o Global.pretrained_model={path/to/weights}/best_accuracy  Global.infer_img=ppstructure/docs/table/table.jpg

推理结果保存至:PaddleOCR-release-2.7/output/infer/SLANet.json

三、踩坑记录

1.AttributeError: 'ParallelEnv' object has no attribute '_device_id'

解决方法:

paddle 2.6.0及以上版本中,应使用dist.get_world_size()代替dist.ParallelEnv().nranks,并且应使用dist.get_rank()代替dist.ParallelEnv().local_rank.

即定位到program.py的677行将内容更改成如下所示:

2.ImportError: libcudart.so.11.0: cannot open shared object file: No such file or directory

 

解决方法:

                首先查看’ libcudart.so.11.0‘该文件是否存在:

                  【命令】 find  【路径】-name libcudart.so.11.0

                   例如: find  /home/hadoop  -name libcudart.so.11.0,结果显示:

选择结果中其中一个进行环境变量修改:

【命令】export LD_LIBRARY_PATH=/home/hadoop/xxx/data/lib:$LD_LIBRARY_PATH

【命令】source ~/.bashrc

重新运行Python,无错误显示即可

3.RuntimeError: (PreconditionNotMet) Cannot load cudnn shared library. Cannot invoke method cudnnGetVersion. [Hint: cudnn_dso_handle should not be null.] (at /paddle/paddle/phi/backends/dynload/cudnn.cc:64)

W0312 17:07:37.135784 19389 gpu_resources.cc:119] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 11.8, Runtime API Version: 11.8
W0312 17:07:37.136477 19389 dynamic_loader.cc:314] The third-party dynamic library (libcudnn.so) that Paddle depends on is not configured correctly. (error code is /usr/local/cuda/lib64/libcudnn.so: cannot open shared object file: No such file or directory)
  Suggestions:
  1. Check if the third-party dynamic library (e.g. CUDA, CUDNN) is installed correctly and its version is matched with paddlepaddle you installed.
  2. Configure third-party dynamic library environment variables as follows:
  - Linux: set LD_LIBRARY_PATH by `export LD_LIBRARY_PATH=...`
  - Windows: set PATH by `set PATH=XXX;
Traceback (most recent call last):

。。。。。。

packages/paddle/nn/initializer/initializer.py", line 40, in __call__
    return self.forward(param, block)
  File "/home/hadoop/anaconda3/envs/esrgan/lib/python3.9/site-packages/paddle/nn/initializer/kaiming.py", line 147, in forward
    out_var = _C_ops.gaussian(
RuntimeError: (PreconditionNotMet) Cannot load cudnn shared library. Cannot invoke method cudnnGetVersion.
  [Hint: cudnn_dso_handle should not be null.] (at /paddle/paddle/phi/backends/dynload/cudnn.cc:64)

解决方法:

定位显示无法找到/usr/local/cuda/lib64/libcudnn.so文件

 

查找该文件的位置:

find -name libcudnn.so

把缺失文件的库所在的lib路径,补充到LD_LIBRARY_PATH环境变量里面。找到该文件的位置,把库文件所在的路径(比如xxx/lib)加入LD_LIBRARY_PATH即可

export LD_LIBRARY_PATH=xxx/lib:$LD_LIBRARY_PATH

(上面方案为临时方案,每次在程序运行前设置环境变量。永久方案将环境变量添加到~/.bashrc文件,添加后需要关闭终端重新打开或者登录

echo "export LD_LIBRARY_PATH=xxx/lib">>~/.bashrc

 补充:常用的镜像源


清华:https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
华中科技大学:http://pypi.hustunique.com/simple/
上海交通大学:https://mirror.sjtu.edu.cn/pypi/web/simple/
豆瓣:http://pypi.douban.com/simple/


安装方式:
pip install <安装包> -i <镜像源>
例如:  pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple/

参考链接:解决paddlepaddle安装过程中遇到的ImportError: libcudart.so.10.2: cannot open shared object file: Nosuch file or-CSDN博客

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/451311.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

k8s-生产级的k8s高可用(2) 25

部署containerd k8s2、k8s3、k8s4在配置前需要重置节点&#xff08;reset&#xff09;在上一章已完成 禁用所有节点docker和cri-docker服务 所有节点清除iptables规则 重置后全部节点重启 由于之前部署过docker&#xff0c;因此containerd默认已安装 修改配置 启动containe…

OpenCV学习笔记(一)——Anaconda下载和OpenCV的下载

OpenCV是图象识别中有巨大的应用场景&#xff0c;本篇文章以Python为基础。当初学OpenCV的时候&#xff0c;推使用在Anaconda编写代码&#xff0c;原因比较方便&#xff0c;下面我们对于Anaconda的下载过程进行演示。 Anaconda的下载 首先打开官网www.anaconda.com/download找…

Midjourney绘图欣赏系列(十)

Midjourney介绍 Midjourney 是生成式人工智能的一个很好的例子&#xff0c;它根据文本提示创建图像。它与 Dall-E 和 Stable Diffusion 一起成为最流行的 AI 艺术创作工具之一。与竞争对手不同&#xff0c;Midjourney 是自筹资金且闭源的&#xff0c;因此确切了解其幕后内容尚不…

力扣701. 二叉搜索树中的插入操作

思路&#xff1a;往二叉搜索树中插入一个值&#xff0c;树的结构有多种符合的情况&#xff0c;那我们可以选一种最容易的插入方式&#xff0c;反正只需要插入一个值而已&#xff0c;我们不难发现&#xff0c;不管插入什么值&#xff0c;都可以安排插入到叶子节点上。 再利用二叉…

uview upicker时间选择器(附Demo)

目录 前言正文 前言 uniapp时间选择器&#xff0c;是upicker&#xff0c;与微信小程序还是有些区别 补充官网的基本知识&#xff1a;uview官网 官网的展示例子如下&#xff1a;&#xff08;但是没Demo&#xff09; 正文 通过上面的展示图&#xff0c;复刻一个类似Demo图&am…

小兔鲜鲜项目(前端vue3)

成果图 大家喜欢给一个赞被&#xff0c; 项目地址&#xff1a;gitee 注意&#xff1a;项目克隆下去之后先运行 npm i之后安装项目插件包之后在npm run dev 运行就可以了

【Mysql】事务与索引

目录 MySQL事务 事务的特性 并发事务的问题&#xff1f; 事务隔离级别&#xff1f; MySQL索引 数据结构 索引类型 聚簇索引与非聚簇索引 聚集索引的优点 聚集索引的缺点 非聚集索引的优点 非聚集索引的缺点 非聚集索引一定回表查询吗(覆盖索引)? 覆盖索引 联合索…

识别恶意IP地址的有效方法

在互联网的环境中&#xff0c;恶意IP地址可能会对网络安全造成严重威胁&#xff0c;例如发起网络攻击、传播恶意软件等。因此&#xff0c;识别恶意IP地址是保护网络安全的重要一环。IP数据云将探讨一些有效的方法来识别恶意IP地址。 IP地址查询&#xff1a;https://www.ipdata…

springboot265基于Spring Boot的库存管理系统

基于Spring Boot库存管理系统 Inventory Meanagement System based on Spring Boot 摘 要 当下&#xff0c;如果还依然使用纸质文档来记录并且管理相关信息&#xff0c;可能会出现很多问题&#xff0c;比如原始文件的丢失&#xff0c;因为采用纸质文档&#xff0c;很容易受潮…

Redis底层核心对象RedisObject源码分析

文章目录 1. redis底层数据结构2. 插入KV底层源码流程分析 1. redis底层数据结构 redis 6数据结构和底层数据结构的关系 String类型本质是SDS动态字符串&#xff0c;即redis层面的数据结构底层会有对应的数据结构实现&#xff0c;上面是redis 6之前的实现 redis 7数据结构和底…

Terrace联合创始人兼CEO Jesse Beller确认出席Hack.Summit() 2024区块链开发者大会

在科技创新的浪潮中&#xff0c;区块链技术以其独特的去中心化、透明性和安全性&#xff0c;正逐渐成为引领未来发展的重要力量。在这样的背景下&#xff0c;备受瞩目的Hack.Summit() 2024区块链开发者大会即将于4月9日至10日在香港数码港盛大举行。本次大会的亮点之一&#xf…

程序员春招攻略:金三银四的求职智慧与机遇

文章目录 程序员的金三银四求职宝典方向一&#xff1a;面试技巧分享自我介绍的艺术技术问题的回答策略团队协作经验的有效展示压力面试的应对结束语的巧妙运用 方向二&#xff1a;面试题解析数据结构与算法题系统设计题编程题 方向三&#xff1a;公司文化解读腾讯&#xff08;T…

软件设计不是CRUD(14):低耦合模块设计理论——行为抽象与设计模式(上)

是不是看到“设计模式”四个字,各位读者就觉得后续内容要开始讲一些假大空的内容了?各位读者是不是有这样的感受,就是单纯讲设计模式的内容,网络上能找到很多资料,但是看过这些资料后读者很难将设计模式运用到实际的工作中。甚至出现了一种声音:设计模式是没有用的,应用…

机试:最大子序列的和

问题描述: 算法思想: 若第(i-1)个序列的小于0,则第i个序列的最大值为nums[i]; 若第(i-1)个序列的小于0,则第i个序列的最大值为max(i-1) nums[i]; 如果max(i-1)>0,max(i)max(i-1)Nums(i) 如果max(i-1)<0,max(i)Nums(i)代码示例: #include <bits/stdc.h> //该算法…

ULTRAL SCALE FPGA TRANSCEIVER速率

CPLL支持2-6.25速率 QPLL支持速率 实际使用CPLL最高可以超过这个&#xff0c;QPLL最低也可以低于这个&#xff0c;xilinx留的阈量还是比较大。

蓝桥杯真题讲解:子矩阵(二维滑动窗口)

蓝桥杯真题讲解&#xff1a;子矩阵&#xff08;二维滑动窗口&#xff09; 一、视频讲解二、正解代码 一、视频讲解 蓝桥杯真题讲解&#xff1a;子矩阵&#xff08;二维滑动窗口&#xff09; 二、正解代码 //二维单调队列 #include<bits/stdc.h> #define endl \n #def…

C# 视频转图片

在 C# 中将视频转换为图像可以使用 FFmpeg 库。下面是一个示例代码来完成这个任务&#xff1a; using System; using System.Diagnostics;class Program {static void Main(string[] args){string inputFile "input_video.mp4"; // 输入的视频文件路径string outpu…

2024.3.12

1. 要求&#xff1a;自己封装一个矩形类(Rect)&#xff0c;拥有私有属性:宽度(width)、高度(height)&#xff0c; 定义公有成员函数: 初始化函数:void init(int w, int h) 更改宽度的函数:set_w(int w) 更改高度的函数:set_h(int h) 输出该矩形的周长和面积函数:void sho…

在VMvare中虚拟机安装centos7和初始设置

下载镜像 阿里云的镜像站&#xff1a;https://mirrors.aliyun.com/centos/7/isos/x86_64/ 创建虚拟机过程 虚拟机创建过程比较简单&#xff0c;以下在VMvare16中进行安装 点击左上角&#xff0c;文件-新建虚拟机&#xff1a; 选择典型 选择刚刚下载好的镜像 输入虚拟机…

Python笔记:函数

Python函数定义规则&#xff1a; 函数代码块以def关键词开头&#xff0c;后接函数标识符名称和圆括号()。任何传入参数和自变量必须放在圆括号中间&#xff0c;圆括号之间可以用于定义参数。return [表达式] 结束函数&#xff0c;选择性地返回一个值给调用方&#xff0c;不带表…
最新文章