-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Description
🔎 Search before asking
- I have searched the PaddleOCR Docs and found no similar bug report.
- I have searched the PaddleOCR Issues and found no similar bug report.
- I have searched the PaddleOCR Discussions and found no similar bug report.
🐛 Bug (问题描述)
Hi community , i would like to ask if you help me with this problem of using the fine-tuned PaddleOCRV5 rec model on my Khmer language dataset. the error of "KeyError: 'Global'" when using inference on finetuned model.
🏃♂️ Environment (运行环境)
OS linux on colab
paddlepadle 3.0.0
python 3.9
🌰 Minimal Reproducible Example (最小可复现问题的Demo)
for training/finetuning
!python3 tools/train.py -c configs/rec/PP-OCRv5/km_PP-OCRv5_rec.yml -o Global.pretrained_model=pretrained_models/PP-OCRv5_mobile_rec_pretrained
config file: km_PP-OCRv5_rec.yml
Global:
debug: false
use_gpu: true
epoch_num: 75
log_smooth_window: 20
print_batch_step: 10
save_model_dir: ./output/km_rec_ppocr_v5
save_epoch_step: 10
eval_batch_step: [0, 1000]
cal_metric_during_train: true
pretrained_model:
checkpoints:
save_inference_dir:
use_visualdl: false
infer_img:
character_dict_path: ./ppocr/utils/dict/km_dict.txt
max_text_length: &max_text_length 25
infer_mode: false
use_space_char: true
distributed: true
save_res_path: ./output/rec/predicts_km_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: 5
regularizer:
name: L2
factor: 3.0e-05
Architecture:
model_type: rec
algorithm: SVTR_LCNet
Transform:
Backbone:
name: PPLCNetV3
scale: 0.95
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
ignore_space: False
Train:
dataset:
name: MultiScaleDataSet
ds_width: false
data_dir: ./train_data/rec/
ext_op_transform_idx: 1
label_file_list:
- ./train_data/rec/train.txt
transforms:
- DecodeImage:
img_mode: BGR
channel_first: false
- RecConAug:
prob: 0.5
ext_data_num: 2
image_shape: [48, 320, 3]
max_text_length: *max_text_length
- RecAug:
- 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: 8
Eval:
dataset:
name: SimpleDataSet
data_dir: ./train_data/rec/
label_file_list:
- ./train_data/rec/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: true
drop_last: false
batch_size_per_card: 64
num_workers: 4
export the model
!FLAGS_enable_pir_api=0 python3 tools/export_model.py
-c configs/rec/PP-OCRv5/km_PP-OCRv5_rec.yml
-o Global.pretrained_model=./output/km_rec_ppocr_v5/best_accuracy.pdparams \
Global.save_inference_dir=./output/inference_model_km_rec_ppocr_v5/
Global.export_with_pir=False
once i exported it , i get these 4 files:
inference.pdiparams
inference.pdiparams.info
inference.pdmodel
inference.yml
inference
from paddleocr import PaddleOCR
ocr = PaddleOCR(rec_model_dir='/content/inference_dir', use_angle_cls=False) # Set use_angle_cls as needed
img_path = '/content/sample.png'
result = ocr.ocr(img_path, cls=False)
for line in result:
for word_info in line:
text = word_info[1][0] # Recognized text
confidence = word_info[1][1] # Confidence score
print(f"Text: {text}, Confidence: {confidence}")
when i tried to use this finetuned model for inference , i get this error:
/usr/local/lib/python3.12/dist-packages/paddlex/inference/models/init.py in create_predictor(model_name, model_dir, device, pp_option, use_hpip, hpi_config, *args, **kwargs)
73 config = BasePredictor.load_config(model_dir)
74 assert (
---> 75 model_name == config["Global"]["model_name"]
76 ), f"Model name mismatch,please input the correct model dir."
77 return BasePredictor.get(model_name)(
KeyError: 'Global'