Skip to content
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

自行训练的模型 转inference后 rec识别准确度低 #4229

Closed
LiYifanyvonne opened this issue Sep 29, 2021 · 6 comments
Closed

自行训练的模型 转inference后 rec识别准确度低 #4229

LiYifanyvonne opened this issue Sep 29, 2021 · 6 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@LiYifanyvonne
Copy link

#2470 问题下已经逐条排查过了,github上能搜到的#2080 #2782 #2873也都排查了
参数已对齐,检测还算准确,但是识别有很大问题
还有什么需要排查的点吗

举例来说:
python tools/infer/predict_system.py --image_dir="./try2/" --det_model_dir="./inference/db_mv3" --rec_model_dir="./inference/rec_ic" --use_angle_cls=false --rec_char_dict_path="./ppocr/utils/cchw_dict.txt" --rec_image_shape="3,32,100"
结果:
20210926174943 pngsub_pic0_1
python tools/infer_rec.py -c configs/rec/rec_icdar15_train.yml -o Global.pretrained_model=./output/rec/ic15/best_accuracy Global.load_static_weights=false Global.infer_img=./try2/
结果:
./try2/20210926174943.pngsub_pic0_1.png 剩余期限 0.83949465

@LDOUBLEV

@LiYifanyvonne LiYifanyvonne changed the title 训练后的模型转inference后准确度下降 自行训练的模型 转inference后 rec识别准确度低 Sep 29, 2021
@LiYifanyvonne
Copy link
Author

LiYifanyvonne commented Sep 29, 2021

rec的yml参数
Global:
use_gpu: false
epoch_num: 1200
log_smooth_window: 20
print_batch_step: 20
save_model_dir: ./output/rec/ic15/
save_epoch_step: 360
#evaluation is run every 2000 iterations
eval_batch_step: [0, 360]
cal_metric_during_train: True
pretrained_model: ./pretrain_models/rec_mv3_none_bilstm_ctc_v2.0_train/best_accuracy
checkpoints:
save_inference_dir:
use_visualdl: False
infer_img: doc/imgs_words_en/word_10.png
#for data or label process
character_dict_path: ./ppocr/utils/cchw_dict.txt
character_type: ch
max_text_length: 25
infer_mode: False
use_space_char: True
save_res_path: ./output/rec/predicts_ic15.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: ./train_data/rec/
label_file_list: ["./train_data/rec/rec_gt_train.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: 2
drop_last: True
num_workers: 1
use_shared_memory: False

Eval:
dataset:
name: SimpleDataSet
data_dir: ./train_data/rec
label_file_list: ["./train_data/rec/rec_gt_test.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: 8
num_workers: 1
use_shared_memory: False

@LiYifanyvonne
Copy link
Author

paddleOCR 代码内对齐的参数
else:
return argparse.Namespace(
use_gpu=False,
ir_optim=True,
use_tensorrt=False,
gpu_mem=8000,
image_dir='',
det_algorithm='DB',
det_model_dir="./inference/db_mv3",#None,
det_limit_side_len=960,
det_limit_type='max',
det_db_thresh=0.3,
det_db_box_thresh=0.6,
det_db_unclip_ratio=1.5,
use_dilation=False,
det_db_score_mode="fast",
det_east_score_thresh=0.8,
det_east_cover_thresh=0.1,
det_east_nms_thresh=0.2,
rec_algorithm='CRNN',
rec_model_dir="./inference/rec_ic",#None,
rec_image_shape="3, 32, 100",#
rec_char_type='ch',
rec_batch_num=2,
max_text_length=25,
rec_char_dict_path="./ppocr/utils/cchw_dict.txt",#None,
use_space_char=True,
drop_score=0.5,
cls_model_dir=None,
cls_image_shape="3, 48, 192",
label_list=['0', '180'],
cls_batch_num=6,
cls_thresh=0.9,
enable_mkldnn=False,
use_zero_copy_run=False,
use_pdserving=False,
lang='ch',
det=True,
rec=True,
use_angle_cls=False)

@ioracion
Copy link
Contributor

你用predict_system是检测+识别,而infer_rec是纯识别。所以可能是加了检测模型才导致结果不对。用predict_rec跟infer_rec对比试试呢

@LiYifanyvonne
Copy link
Author

LiYifanyvonne commented Sep 30, 2021

你用predict_system是检测+识别,而infer_rec是纯识别。所以可能是加了检测模型才导致结果不对。用predict_rec跟infer_rec对比试试呢

用语句python tools/infer/predict_rec.py --image_dir="./try3/" --rec_model_dir="./inference/rec_ic" --rec_char_dict_path="./ppocr/utils/cchw_dict.txt" --rec_image_shape="3,32,100"

结果:
微信图片_20210930110432

的确可能是检测的问题,但是用predict_system时,检测框选的是正确的。
而且检测参数也对齐过的

Global:
use_gpu: false
epoch_num: 30
log_smooth_window: 20
print_batch_step: 10
save_model_dir: ./output/db_mv3/
save_epoch_step: 15
#evaluation is run every 2000 iterations
eval_batch_step: [0,15]
cal_metric_during_train: False
pretrained_model: ./pretrain_models/ch_ppocr_mobile_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: MobileNetV3
scale: 0.5
model_name: large
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:
learning_rate: 0.001
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: ./train_data/
label_file_list:
- ./train_data/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: [640, 640]
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: 16
num_workers: 1
use_shared_memory: False

Eval:
dataset:
name: SimpleDataSet
data_dir: ./train_data/
label_file_list:
- ./train_data/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: 1
use_shared_memory: False

@ioracion
Copy link
Contributor

emmm这样的图片其实没有必要用检测模型,字基本占了整张图,去掉检测模型速度还更快

@Evezerest Evezerest added the good first issue Good for newcomers label Oct 8, 2021
@paddle-bot-old
Copy link

Since you haven't replied for more than 3 months, we have closed this issue/pr.
If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up.
It is recommended to pull and try the latest code first.
由于您超过三个月未回复,我们将关闭这个issue/pr。
若问题未解决或有后续问题,请随时重新打开(建议先拉取最新代码进行尝试),我们会继续跟进。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants