Jelajahi Sumber

fix PP-OCRv4_mobile_det config

zhangyubo0722 1 tahun lalu
induk
melakukan
f4fc45742e

+ 39 - 0
paddlex/configs/table_recognition/SLANet_plus.yaml

@@ -0,0 +1,39 @@
+Global:
+  model: SLANet_plus
+  mode: check_dataset # check_dataset/train/evaluate/predict
+  dataset_dir: "/paddle/dataset/paddlex/table_rec/table_rec_dataset_examples"
+  device: gpu:0,1,2,3
+  output: "output"
+
+CheckDataset:
+  convert:
+    enable: False
+    src_dataset_type: null
+  split:
+    enable: False
+    train_percent: null
+    val_percent: null
+
+Train:
+  epochs_iters: 10
+  batch_size: 48
+  learning_rate: 0.001
+  pretrain_weight_path: null
+  resume_path: null
+  log_interval: 20
+  eval_interval: 1
+  save_interval: 1
+
+Evaluate:
+  weight_path: "output/best_accuracy/best_accuracy.pdparams"
+  log_interval: 1
+
+Export:
+  weight_path: https://paddleocr.bj.bcebos.com/pretrained/ch_PP-StructrureV2_SLANet_plus_trained.pdparams
+
+Predict:
+  batch_size: 1
+  model_dir: "output/best_accuracy/inference"
+  input: "https://paddle-model-ecology.bj.bcebos.com/paddlex/imgs/demo_image/table_recognition.jpg"
+  kernel_option:
+    run_mode: paddle

+ 1 - 0
paddlex/inference/utils/official_models.py

@@ -212,6 +212,7 @@ PP-LCNet_x1_0_pedestrian_attribute_infer.tar",
 PP-LCNet_x1_0_vehicle_attribute_infer.tar",
     "PicoDet_layout_1x": "https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b1_v2/PicoDet_layout_1x_infer.tar",
     "SLANet": "https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b1_v2/SLANet_infer.tar",
+    "SLANet_plus": "https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b1_v2/SLANet_plus_infer.tar",
     "LaTeX_OCR_rec": "https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b1_v2/LaTeX_OCR_rec_infer.tar",
     "FasterRCNN-ResNet34-FPN": "https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b1_v2/FasterRCNN-ResNet34-FPN_infer.tar",
     "FasterRCNN-ResNet50": "https://paddle-model-ecology.bj.bcebos.com/paddlex/official_inference_model/paddle3.0b1_v2/FasterRCNN-ResNet50_infer.tar",

+ 1 - 0
paddlex/modules/table_recognition/model_list.py

@@ -15,4 +15,5 @@
 
 MODELS = [
     "SLANet",
+    "SLANet_plus",
 ]

+ 3 - 0
paddlex/modules/text_recognition/dataset_checker/__init__.py

@@ -24,6 +24,9 @@ from ...base import BaseDatasetChecker
 from .dataset_src import check, split_dataset, deep_analyse, convert
 
 from ..model_list import MODELS
+from ...formula_recognition.model_list import MODELS as MODELS_LaTeX
+
+MODELS = MODELS + MODELS_LaTeX
 
 
 class TextRecDatasetChecker(BaseDatasetChecker):

+ 3 - 0
paddlex/modules/text_recognition/evaluator.py

@@ -17,6 +17,9 @@ from pathlib import Path
 
 from ..base import BaseEvaluator
 from .model_list import MODELS
+from ..formula_recognition.model_list import MODELS as MODELS_LaTeX
+
+MODELS = MODELS + MODELS_LaTeX
 
 
 class TextRecEvaluator(BaseEvaluator):

+ 3 - 0
paddlex/modules/text_recognition/exportor.py

@@ -14,6 +14,9 @@
 
 from ..base import BaseExportor
 from .model_list import MODELS
+from ..formula_recognition.model_list import MODELS as MODELS_LaTeX
+
+MODELS = MODELS + MODELS_LaTeX
 
 
 class TextRecExportor(BaseExportor):

+ 3 - 0
paddlex/modules/text_recognition/trainer.py

@@ -21,6 +21,9 @@ import lazy_paddle as paddle
 from ..base import BaseTrainer
 from ...utils.config import AttrDict
 from .model_list import MODELS
+from ..formula_recognition.model_list import MODELS as MODELS_LaTeX
+
+MODELS = MODELS + MODELS_LaTeX
 
 
 class TextRecTrainer(BaseTrainer):

+ 1 - 1
paddlex/pipelines/table_recognition.yaml

@@ -4,7 +4,7 @@ Global:
   
 Pipeline:
   layout_model: PicoDet_layout_1x
-  table_model: SLANet
+  table_model: SLANet_plus
   text_det_model: PP-OCRv4_mobile_det
   text_rec_model: PP-OCRv4_mobile_rec
   layout_batch_size: 1

+ 141 - 0
paddlex/repo_apis/PaddleOCR_api/configs/SLANet_plus.yaml

@@ -0,0 +1,141 @@
+Global:
+  use_gpu: True
+  epoch_num: 10
+  log_smooth_window: 20
+  print_batch_step: 20
+  save_model_dir: ./output/SLANet_ch
+  save_epoch_step: 400
+  # evaluation is run every 331 iterations after the 0th iteration
+  eval_batch_step: [0, 100]
+  cal_metric_during_train: True
+  pretrained_model: 
+  checkpoints: 
+  save_inference_dir: ./output/SLANet_ch/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_ch.txt
+  character_type: en
+  max_text_length: &max_text_length 500
+  box_format: &box_format xyxyxyxy # 'xywh', 'xyxy', 'xyxyxyxy'
+  infer_mode: False
+  use_sync_bn: True
+  save_res_path: output/infer
+
+Optimizer:
+  name: Adam
+  beta1: 0.9
+  beta2: 0.999
+  clip_norm: 5.0
+  lr:
+    learning_rate: 0.001
+  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 8
+
+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
+  del_thead_tbody: True
+
+Train:
+  dataset:
+    name: PubTabTableRecDataset
+    data_dir: train_data/table/train/
+    label_file_list: [train_data/table/train.txt]
+    transforms:
+      - DecodeImage:
+          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: 48
+    drop_last: True
+    num_workers: 1
+
+Eval:
+  dataset:
+    name: PubTabTableRecDataset
+    data_dir: train_data/table/val/
+    label_file_list: [train_data/table/val.txt]
+    transforms:
+      - DecodeImage:
+          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: 48
+    num_workers: 1

+ 10 - 0
paddlex/repo_apis/PaddleOCR_api/table_rec/register.py

@@ -44,3 +44,13 @@ register_model_info(
         "hpi_config_path": HPI_CONFIG_DIR / "SLANet.yaml",
     }
 )
+
+register_model_info(
+    {
+        "model_name": "SLANet_plus",
+        "suite": "TableRec",
+        "config_path": osp.join(PDX_CONFIG_DIR, "SLANet_plus.yaml"),
+        "supported_apis": ["train", "evaluate", "predict", "export"],
+        "hpi_config_path": HPI_CONFIG_DIR / "SLANet.yaml",
+    }
+)

+ 1 - 1
paddlex/repo_apis/PaddleOCR_api/text_det/register.py

@@ -40,7 +40,7 @@ register_model_info(
     {
         "model_name": "PP-OCRv4_mobile_det",
         "suite": "TextDet",
-        "config_path": osp.join(PDX_CONFIG_DIR, "PP-OCRv4_mobile_seal_det.yaml"),
+        "config_path": osp.join(PDX_CONFIG_DIR, "PP-OCRv4_mobile_det.yaml"),
         "supported_apis": ["train", "evaluate", "predict", "export"],
         "hpi_config_path": HPI_CONFIG_DIR / "PP-OCRv4_mobile_det.yaml",
     }