Compare commits
2 Commits
7c0ed23362
...
5a87e37bb2
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a87e37bb2 | |||
| 206c2a6877 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -13,6 +13,7 @@ output/
|
||||
train_data/
|
||||
pretrained_models/
|
||||
log/
|
||||
tags
|
||||
*.DS_Store
|
||||
*.vs
|
||||
*.user
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
Global:
|
||||
model_name: PP-OCRv5_server_rec # To use static model for inference.
|
||||
debug: false
|
||||
use_gpu: true
|
||||
use_gpu: false
|
||||
epoch_num: 75
|
||||
log_smooth_window: 20
|
||||
print_batch_step: 10
|
||||
save_model_dir: /kaggle/output/PP-OCRv5_server_rec
|
||||
save_model_dir: output/PP-OCRv5_server_rec
|
||||
save_epoch_step: 1
|
||||
eval_batch_step: [0, 2000]
|
||||
cal_metric_during_train: true
|
||||
@@ -14,13 +14,13 @@ Global:
|
||||
checkpoints:
|
||||
save_inference_dir:
|
||||
use_visualdl: false
|
||||
infer_img: /kaggle/input/custom-ocr-dataset/images/1C4HJXEN3MW645094.jpg
|
||||
character_dict_path: /kaggle/input/custom-ocr-dataset/dict.txt
|
||||
infer_img: train_data/images/1C4HJXEN3MW645094.jpg
|
||||
character_dict_path: train_data/dict.txt
|
||||
max_text_length: &max_text_length 19
|
||||
infer_mode: false
|
||||
use_space_char: true
|
||||
distributed: true
|
||||
save_res_path: /kaggle/output/rec/predicts_ppocrv5.txt
|
||||
save_res_path: output/rec/predicts_ppocrv5.txt
|
||||
d2s_train_image_shape: [3, 48, 320]
|
||||
|
||||
|
||||
@@ -78,10 +78,10 @@ Train:
|
||||
dataset:
|
||||
name: MultiScaleDataSet
|
||||
ds_width: false
|
||||
data_dir: /kaggle/input/custom-ocr-dataset/images
|
||||
data_dir: train_data/images
|
||||
ext_op_transform_idx: 1
|
||||
label_file_list:
|
||||
- /kaggle/input/custom-ocr-dataset/train.txt
|
||||
- train_data/train.txt
|
||||
transforms:
|
||||
- DecodeImage:
|
||||
img_mode: BGR
|
||||
@@ -110,9 +110,9 @@ Train:
|
||||
Eval:
|
||||
dataset:
|
||||
name: SimpleDataSet
|
||||
data_dir: /kaggle/input/custom-ocr-dataset/images
|
||||
data_dir: train_data/images
|
||||
label_file_list:
|
||||
- /kaggle/input/custom-ocr-dataset/val.txt
|
||||
- train_data/val.txt
|
||||
transforms:
|
||||
- DecodeImage:
|
||||
img_mode: BGR
|
||||
|
||||
135
configs/rec_custom_kaggle.yml
Normal file
135
configs/rec_custom_kaggle.yml
Normal file
@@ -0,0 +1,135 @@
|
||||
Global:
|
||||
model_name: PP-OCRv5_server_rec # To use static model for inference.
|
||||
debug: false
|
||||
use_gpu: true
|
||||
epoch_num: 75
|
||||
log_smooth_window: 20
|
||||
print_batch_step: 10
|
||||
save_model_dir: /kaggle/output/PP-OCRv5_server_rec
|
||||
save_epoch_step: 1
|
||||
eval_batch_step: [0, 2000]
|
||||
cal_metric_during_train: true
|
||||
calc_epoch_interval: 1
|
||||
pretrained_model: https://paddle-model-ecology.bj.bcebos.com/paddlex/official_pretrained_model/PP-OCRv5_server_rec_pretrained.pdparams
|
||||
checkpoints:
|
||||
save_inference_dir:
|
||||
use_visualdl: false
|
||||
infer_img: /kaggle/input/custom-ocr-dataset/images/1C4HJXEN3MW645094.jpg
|
||||
character_dict_path: /kaggle/input/custom-ocr-dataset/dict.txt
|
||||
max_text_length: &max_text_length 19
|
||||
infer_mode: false
|
||||
use_space_char: true
|
||||
distributed: true
|
||||
save_res_path: /kaggle/output/rec/predicts_ppocrv5.txt
|
||||
d2s_train_image_shape: [3, 48, 320]
|
||||
|
||||
|
||||
Optimizer:
|
||||
name: Adam
|
||||
beta1: 0.9
|
||||
beta2: 0.999
|
||||
lr:
|
||||
name: Cosine
|
||||
learning_rate: 0.0005
|
||||
warmup_epoch: 1
|
||||
regularizer:
|
||||
name: L2
|
||||
factor: 3.0e-05
|
||||
|
||||
|
||||
Architecture:
|
||||
model_type: rec
|
||||
algorithm: SVTR_HGNet
|
||||
Transform:
|
||||
Backbone:
|
||||
name: PPHGNetV2_B4
|
||||
text_rec: True
|
||||
Head:
|
||||
name: MultiHead
|
||||
head_list:
|
||||
- CTCHead:
|
||||
Neck:
|
||||
name: svtr
|
||||
dims: 120
|
||||
depth: 2
|
||||
hidden_dims: 120
|
||||
kernel_size: [1, 3]
|
||||
use_guide: True
|
||||
Head:
|
||||
fc_decay: 0.00001
|
||||
- NRTRHead:
|
||||
nrtr_dim: 384
|
||||
max_text_length: *max_text_length
|
||||
|
||||
Loss:
|
||||
name: MultiLoss
|
||||
loss_config_list:
|
||||
- CTCLoss:
|
||||
- NRTRLoss:
|
||||
|
||||
PostProcess:
|
||||
name: CTCLabelDecode
|
||||
|
||||
Metric:
|
||||
name: RecMetric
|
||||
main_indicator: acc
|
||||
|
||||
Train:
|
||||
dataset:
|
||||
name: MultiScaleDataSet
|
||||
ds_width: false
|
||||
data_dir: /kaggle/input/custom-ocr-dataset/images
|
||||
ext_op_transform_idx: 1
|
||||
label_file_list:
|
||||
- /kaggle/input/custom-ocr-dataset/train.txt
|
||||
transforms:
|
||||
- DecodeImage:
|
||||
img_mode: BGR
|
||||
channel_first: false
|
||||
- MultiLabelEncode:
|
||||
gtc_encode: NRTRLabelEncode
|
||||
- KeepKeys:
|
||||
keep_keys:
|
||||
- image
|
||||
- label_ctc
|
||||
- label_gtc
|
||||
- length
|
||||
- valid_ratio
|
||||
sampler:
|
||||
name: MultiScaleSampler
|
||||
scales: [[320, 32], [320, 48], [320, 64]]
|
||||
first_bs: &bs 128
|
||||
fix_bs: false
|
||||
divided_factor: [8, 16] # w, h
|
||||
is_training: True
|
||||
loader:
|
||||
shuffle: true
|
||||
batch_size_per_card: *bs
|
||||
drop_last: true
|
||||
num_workers: 16
|
||||
Eval:
|
||||
dataset:
|
||||
name: SimpleDataSet
|
||||
data_dir: /kaggle/input/custom-ocr-dataset/images
|
||||
label_file_list:
|
||||
- /kaggle/input/custom-ocr-dataset/val.txt
|
||||
transforms:
|
||||
- DecodeImage:
|
||||
img_mode: BGR
|
||||
channel_first: false
|
||||
- MultiLabelEncode:
|
||||
gtc_encode: NRTRLabelEncode
|
||||
- RecResizeImg:
|
||||
image_shape: [3, 48, 320]
|
||||
- KeepKeys:
|
||||
keep_keys:
|
||||
- image
|
||||
- label_ctc
|
||||
- label_gtc
|
||||
- length
|
||||
- valid_ratio
|
||||
loader:
|
||||
shuffle: false
|
||||
drop_last: false
|
||||
batch_size_per_card: 128
|
||||
num_workers: 4
|
||||
27
scripts/rec_validation.py
Normal file
27
scripts/rec_validation.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
from paddleocr import TextRecognition
|
||||
|
||||
ocr = TextRecognition(
|
||||
model_name="PP-OCRv5_server_rec"
|
||||
# model_dir="output/PP-OCRv5_server_rec_vin"
|
||||
)
|
||||
|
||||
with open("train_data/val.txt", "r") as label_file:
|
||||
lines = label_file.readlines()
|
||||
total = len(lines)
|
||||
matches, mismatches = 0, 0
|
||||
for idx, line in enumerate(lines, start=1):
|
||||
file_name, label = line.split("\t")
|
||||
label = label.strip()
|
||||
path = os.path.join("train_data", os.path.join("images", file_name))
|
||||
result = ocr.predict(path)
|
||||
print(f"{idx}/{total} ", end="")
|
||||
if result[0]["rec_text"] and result[0]["rec_text"] == label:
|
||||
print(f"match {label}")
|
||||
matches += 1
|
||||
else:
|
||||
print(f"mismatch {label}")
|
||||
mismatches += 1
|
||||
|
||||
print(f"{matches} matches of {total}")
|
||||
print(f"{mismatches} mismatches of {total}")
|
||||
27
scripts/score_validation.py
Normal file
27
scripts/score_validation.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
from paddleocr import PaddleOCR
|
||||
from typing import Optional
|
||||
|
||||
ocr = PaddleOCR(rec_model_dir="output/vin_rec_inference")
|
||||
|
||||
def get_best_accuracy(ocr: PaddleOCR, file_path: str) -> Optional[tuple[str, float]]:
|
||||
result = ocr.predict(file_path)
|
||||
texts_with_scores = [item for item in filter(
|
||||
lambda x: len(x[0]) == 17,
|
||||
zip(result[0]["rec_texts"], result[0]["rec_scores"])
|
||||
)]
|
||||
if texts_with_scores:
|
||||
return max(
|
||||
texts_with_scores,
|
||||
key=lambda y: y[1]
|
||||
)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
with open("train_data/val.txt", "r") as label_file:
|
||||
for line in label_file.readlines():
|
||||
file_name, label = line.split("\t")
|
||||
path = os.path.join("train_data", os.path.join("images", file_name))
|
||||
print(file_name)
|
||||
print(get_best_accuracy(ocr, path))
|
||||
Reference in New Issue
Block a user