PaddleOCR系列-基础知识

0. 制作docker环境

sudo docker run -itd  -h simpleedu_paddleocr_wxd --name simpleedu_paddleocr_wxd --restart=always -v /kolla/wxd/opt/wxd/dockerfile/paddleocr:/home/simpleai/workspace/work/paddleocr -p 28866:8866 -p 28867:8867 -p 28888:8888 227dfbb7853c

1. 制作数据集

2. 训练自己的文本检测模型

python3 tools/train.py -c configs/det/ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml

ch_ppocr_v2.0/ch_det_res18_db_v2.0.yml配置如下

Global:
  use_gpu: true
  epoch_num: 1200
  log_smooth_window: 20
  print_batch_step: 2
  save_model_dir: /home/simpleai/workspace/work/paddleocr/model/train_model/ch_db_res18/
  save_epoch_step: 1200
  # evaluation is run every 5000 iterations after the 4000th iteration
  eval_batch_step: [3000, 2000]
  cal_metric_during_train: False
  pretrained_model: /home/simpleai/workspace/work/paddleocr/model/pretrain_models/text_localization/ch_ppocr_server_v2.0_det/ch_ppocr_server_v2.0_det_train/best_accuracy
  checkpoints:
  save_inference_dir:
  use_visualdl: False
  infer_img: doc/imgs_en/img_10.jpg
  save_res_path: ./output/det_db/predicts_db.txt

Architecture:
  model_type: det
  algorithm: DB
  Transform:
  Backbone:
    name: ResNet
    layers: 18
    disable_se: True
  Neck:
    name: DBFPN
    out_channels: 256
  Head:
    name: DBHead
    k: 50

Loss:
  name: DBLoss
  balance_loss: true
  main_loss_type: DiceLoss
  alpha: 5
  beta: 10
  ohem_ratio: 3

Optimizer:
  name: Adam
  beta1: 0.9
  beta2: 0.999
  lr:
    name: Cosine
    learning_rate: 0.001
    warmup_epoch: 2
  regularizer:
    name: 'L2'
    factor: 0

PostProcess:
  name: DBPostProcess
  thresh: 0.3
  box_thresh: 0.6
  max_candidates: 1000
  unclip_ratio: 1.5

Metric:
  name: DetMetric
  main_indicator: hmean

Train:
  dataset:
    name: SimpleDataSet
    data_dir: /home/simpleai/workspace/work/paddleocr/data/text_localization/
    label_file_list:
      - /home/simpleai/workspace/work/paddleocr/data/text_localization/train_label.txt
    ratio_list: [1.0]
    transforms:
      - DecodeImage: # load image
          img_mode: BGR
          channel_first: False
      - DetLabelEncode: # Class handling label
      - IaaAugment:
          augmenter_args:
            - { 'type': Fliplr, 'args': { 'p': 0.5 } }
            - { 'type': Affine, 'args': { 'rotate': [-10, 10] } }
            - { 'type': Resize, 'args': { 'size': [0.5, 3] } }
      - EastRandomCropData:
          size: [960, 960]
          max_tries: 50
          keep_ratio: true
      - MakeBorderMap:
          shrink_ratio: 0.4
          thresh_min: 0.3
          thresh_max: 0.7
      - MakeShrinkMap:
          shrink_ratio: 0.4
          min_text_size: 8
      - NormalizeImage:
          scale: 1./255.
          mean: [0.485, 0.456, 0.406]
          std: [0.229, 0.224, 0.225]
          order: 'hwc'
      - ToCHWImage:
      - KeepKeys:
          keep_keys: ['image', 'threshold_map', 'threshold_mask', 'shrink_map', 'shrink_mask'] # the order of the dataloader list
  loader:
    shuffle: True
    drop_last: False
    batch_size_per_card: 2
    num_workers: 0

Eval:
  dataset:
    name: SimpleDataSet
    data_dir: /home/simpleai/workspace/work/paddleocr/data/text_localization/
    label_file_list:
      - /home/simpleai/workspace/work/paddleocr/data/text_localization/test_label.txt
    transforms:
      - DecodeImage: # load image
          img_mode: BGR
          channel_first: False
      - DetLabelEncode: # Class handling label
      - DetResizeForTest:
#           image_shape: [736, 1280]
      - NormalizeImage:
          scale: 1./255.
          mean: [0.485, 0.456, 0.406]
          std: [0.229, 0.224, 0.225]
          order: 'hwc'
      - ToCHWImage:
      - KeepKeys:
          keep_keys: ['image', 'shape', 'polys', 'ignore_tags']
  loader:
    shuffle: False
    drop_last: False
    batch_size_per_card: 1 # must be 1
    num_workers: 0

3. 训练自己的文本识别模型

4. 模型转换

5. 模型部署

10. 错误解决

  • 1. ImportError: libGL.so.1: cannot open shared object file: No such file or directory
sudo apt update
sudo apt install libgl1-mesa-glx
  • 2. ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory
sudo apt update
sudo apt install libglib2.0-dev
  • 3. libcudart.so.10.2: cannot open shared object file: No such file or directory
未完待续
  • 3. pip安装中https不能访问问题
sudo echo "nameserver 8.8.8.8" | tee /etc/resolv.conf > /dev/null

参考:
1:PaddleOCR训练自己的数据集
2:PaddleOCR v1.1 使用教程

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
PaddleOCR PP-Structurev2是一个基于PaddlePaddle深度学习框架的OCR工具,可以实现文字识别、表格识别、印章识别等功能。以下是PP-Structurev2的使用教程: 1. 安装PaddleOCR 首先需要安装PaddleOCR。可以使用以下命令进行安装: ``` pip install paddleocr ``` 2. 下载PP-Structurev2模型 PP-Structurev2依赖于特定的模型,需要下载对应的模型文件。可以从PaddleOCR的GitHub仓库中下载: ``` git clone https://github.com/PaddlePaddle/PaddleOCR.git cd PaddleOCR wget https://paddleocr.bj.bcebos.com/PP-Structure_v2/ch/ch_ppocr_server_v2.0_rec_infer.tar wget https://paddleocr.bj.bcebos.com/PP-Structure_v2/ch/ch_ppocr_mobile_v2.0_cls_infer.tar wget https://paddleocr.bj.bcebos.com/PP-Structure_v2/ch/ch_ppocr_mobile_v2.0_det_infer.tar tar xf ch_ppocr_server_v2.0_rec_infer.tar tar xf ch_ppocr_mobile_v2.0_cls_infer.tar tar xf ch_ppocr_mobile_v2.0_det_infer.tar ``` 3. 使用PP-Structurev2 使用PP-Structurev2需要先加载模型。可以使用以下代码加载模型: ``` import paddleocr ocr = paddleocr.OCR( det_model_dir='ch_ppocr_mobile_v2.0_det_infer', rec_model_dir='ch_ppocr_server_v2.0_rec_infer', cls_model_dir='ch_ppocr_mobile_v2.0_cls_infer', use_angle_cls=True, lang='ch' ) ``` 加载模型后,就可以使用PP-Structurev2进行文字识别、表格识别、印章识别等操作。以下是一些示例代码: ``` # 文字识别 result = ocr.ocr('example.jpg') for line in result: print(line) # 表格识别 result = ocr.table_ocr('example.jpg') for table in result: for row in table: print(row) # 印章识别 result = ocr.seal_ocr('example.jpg') print(result) ``` 以上就是PP-Structurev2的使用教程。需要注意的是,PP-Structurev2的模型文件比较大,下载和加载模型可能需要花费一些时间。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

GeekPlusA

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值