-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Loss of accuracy in recognizing when exporting a trained model #11551
Comments
What command did you use to predict?
|
An error occurs when executing this command (venv) PS C:\Studies\Practice> python PaddleOCR/tools/infer/predict_rec.py --image_dir="C:\Users\Mark\Downloads\dataset2\oi_9988.jpg" --rec_model_dir="C:\Studies\Practice\mark2.0" --rec_image_shape="3, 32, 100" --rec_char_dict_path="../Practice1/ppocr/utils/dict1.txt" [2024/01/30 22:27:02] ppocr INFO: In PP-OCRv3, rec_image_shape parameter defaults to '3, 48, 320', if you are using recognition model with PP-OCRv2 or an older version, please set --rec_image_shape='3,32,320 [2024/01/30 22:27:02] ppocr INFO: list index out of range What could be the reason for this? |
I have achieved ~98% accuracy during training. I want to use my trained model in code, for example, instead of typing the command in the terminal every time. But when using this code and the final output model based on my trained model on the dataset where I previously performed validation, I am getting only 5% accuracy. Why does it happen like this? |
Please confirm whether the dictionary used in the training and exported configuration file is ../Practice1/ppocr/utils/dict1.txt. |
As you said, you achieved 98% accuracy on the text recognition evaluation set, and you also need to select a single text recognition prediction in order to align the behavior when making predictions.
Refer to the introduction in the documentation:https://github.com/PaddlePaddle/PaddleOCR/blob/release/2.7/doc/doc_en/whl_en.md |
Yes, I use a dictionary located at this path (../Practice1/ppocr/utils/dict1.txt) throughout the entire model training |
maybe you could print text_id and len(self.character) in File "C:\Studies\Practice\PaddleOCR\ppocr\postprocess\rec_postprocess.py" Line84, to find the reason of IndexError. |
I was able to figure out how to run the above command and it gives the correct answer, but there is a problem.
Code:
|
All parameters need to be consistent, try code:
|
Even when using my output model in this code, nothing changes in the results. |
System Environment: Windows 11, Python 3.9.9
Version: Paddle 2.7+ PaddleOCR
I trained a recognition model using the configuration file config.yml and obtained excellent results on my dataset. However, after exporting the model for inference, the accuracy significantly decreases.
Command code:
python PaddleOCR/tools/export_model.py -c config.yml -o Global.pretrained_model="output/rec/mark/best_accuracy" Global.save_inference_dir=./mark
Configuration file:
Global:
use_gpu: true
epoch_num: 250
log_smooth_window: 20
print_batch_step: 10
save_model_dir: ./output/rec/mark1/
save_epoch_step: 3
eval_batch_step: [0, 2000]
cal_metric_during_train: True
pretrained_model:
checkpoints:
save_inference_dir: ./mark
use_visualdl: TRue
infer_img: doc/imgs_words_en/word_10.png
character_dict_path: ../Practice1/ppocr/utils/dict1.txt
character_type: EN
max_text_length: 25
infer_mode: True
use_space_char: False
save_res_path: ./output/rec/dict1_0.txt
Optimizer:
name: Adam
beta1: 0.9
beta2: 0.999
lr:
learning_rate: 0.0005
regularizer:
name: 'L2'
factor: 0
Architecture:
model_type: rec
algorithm: CRNN
Transform:
Backbone:
name: MobileNetV3
scale: 0.5
model_name: large
Neck:
name: SequenceEncoder
encoder_type: rnn
hidden_size: 96
Head:
name: CTCHead
fc_decay: 0
Loss:
name: CTCLoss
PostProcess:
name: CTCLabelDecode
Metric:
name: RecMetric
main_indicator: acc
Train:
dataset:
name: SimpleDataSet
data_dir: ../Practice1/dataset/train/images/
label_file_list: ['../Practice1/dataset/train/train_annotation.txt']
transforms:
- DecodeImage: # load image
img_mode: BGR
channel_first: False
- CTCLabelEncode: # Class handling label
- RecResizeImg:
image_shape: [3, 32, 100]
- KeepKeys:
keep_keys: ['image', 'label', 'length'] # dataloader will return list in this order
loader:
shuffle: True
batch_size_per_card: 256
drop_last: True
num_workers: 8
use_shared_memory: False
Eval:
dataset:
name: SimpleDataSet
data_dir: ../Practice1/dataset/val/images/
label_file_list: ['../Practice1/dataset/val/val_annotation.txt']
transforms:
- DecodeImage: # load image
img_mode: BGR
channel_first: False
- CTCLabelEncode: # Class handling label
- RecResizeImg:
image_shape: [3, 32, 100]
- KeepKeys:
keep_keys: ['image', 'label', 'length'] # dataloader will return list in this order
loader:
shuffle: False
drop_last: False
batch_size_per_card: 256
num_workers: 4
use_shared_memory: False
The text was updated successfully, but these errors were encountered: