From 4cb824537a4c2924fe133d2d750131389d32360d Mon Sep 17 00:00:00 2001 From: Topdu <784990967@qq.com> Date: Tue, 17 Aug 2021 13:37:32 +0000 Subject: [PATCH] add rec_nrtr --- configs/rec/rec_mtb_nrtr.yml | 18 +--- ppocr/data/imaug/label_ops.py | 2 +- ppocr/metrics/rec_metric.py | 4 +- ppocr/modeling/architectures/base_model.py | 1 - ppocr/modeling/backbones/__init__.py | 2 +- ppocr/modeling/heads/rec_nrtr_optim_head.py | 4 - ppocr/postprocess/rec_postprocess.py | 2 +- ppocr/utils/dict_99.txt | 95 --------------------- 8 files changed, 6 insertions(+), 122 deletions(-) delete mode 100644 ppocr/utils/dict_99.txt diff --git a/configs/rec/rec_mtb_nrtr.yml b/configs/rec/rec_mtb_nrtr.yml index 86a833c5..d16657d8 100644 --- a/configs/rec/rec_mtb_nrtr.yml +++ b/configs/rec/rec_mtb_nrtr.yml @@ -3,38 +3,22 @@ Global: epoch_num: 21 log_smooth_window: 20 print_batch_step: 10 -<<<<<<< HEAD - save_model_dir: ./output/rec/nrtr_final/ + save_model_dir: ./output/rec/nrtr/ save_epoch_step: 1 # evaluation is run every 2000 iterations eval_batch_step: [0, 2000] cal_metric_during_train: True -======= - save_model_dir: ./output/rec/piloptimnrtr/ - save_epoch_step: 1 - # evaluation is run every 2000 iterations - eval_batch_step: [0, 2000] - cal_metric_during_train: False ->>>>>>> 9c67a7f... add rec_nrtr pretrained_model: checkpoints: save_inference_dir: use_visualdl: False infer_img: doc/imgs_words_en/word_10.png # for data or label process -<<<<<<< HEAD character_dict_path: character_type: EN_symbol max_text_length: 25 infer_mode: False use_space_char: True -======= - character_dict_path: ppocr/utils/dict_99.txt - character_type: dict_99 - max_text_length: 25 - infer_mode: False - use_space_char: False ->>>>>>> 9c67a7f... add rec_nrtr save_res_path: ./output/rec/predicts_nrtr.txt Optimizer: diff --git a/ppocr/data/imaug/label_ops.py b/ppocr/data/imaug/label_ops.py index a233738c..39ff8930 100644 --- a/ppocr/data/imaug/label_ops.py +++ b/ppocr/data/imaug/label_ops.py @@ -96,7 +96,7 @@ class BaseRecLabelEncode(object): 'ch', 'en', 'EN_symbol', 'french', 'german', 'japan', 'korean', 'EN', 'it', 'xi', 'pu', 'ru', 'ar', 'ta', 'ug', 'fa', 'ur', 'rs', 'oc', 'rsc', 'bg', 'uk', 'be', 'te', 'ka', 'chinese_cht', 'hi', - 'mr', 'ne', 'latin', 'arabic', 'cyrillic', 'devanagari','dict_99' + 'mr', 'ne', 'latin', 'arabic', 'cyrillic', 'devanagari' ] assert character_type in support_character_type, "Only {} are supported now but get {}".format( support_character_type, character_type) diff --git a/ppocr/metrics/rec_metric.py b/ppocr/metrics/rec_metric.py index 3712e6e9..e4b65a50 100644 --- a/ppocr/metrics/rec_metric.py +++ b/ppocr/metrics/rec_metric.py @@ -30,7 +30,7 @@ class RecMetric(object): target = target.replace(" ", "") norm_edit_dis += Levenshtein.distance(pred, target) / max( len(pred), len(target), 1) - if pred.lower() == target.lower(): + if pred == target: correct_num += 1 all_num += 1 self.correct_num += correct_num @@ -57,4 +57,4 @@ class RecMetric(object): self.correct_num = 0 self.all_num = 0 self.norm_edit_dis = 0 - \ No newline at end of file + diff --git a/ppocr/modeling/architectures/base_model.py b/ppocr/modeling/architectures/base_model.py index 66da4b33..52ad1593 100644 --- a/ppocr/modeling/architectures/base_model.py +++ b/ppocr/modeling/architectures/base_model.py @@ -14,7 +14,6 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function -import paddle from paddle import nn from ppocr.modeling.transforms import build_transform from ppocr.modeling.backbones import build_backbone diff --git a/ppocr/modeling/backbones/__init__.py b/ppocr/modeling/backbones/__init__.py index 73afbe11..49c34864 100755 --- a/ppocr/modeling/backbones/__init__.py +++ b/ppocr/modeling/backbones/__init__.py @@ -27,7 +27,7 @@ def build_backbone(config, model_type): from .rec_resnet_fpn import ResNetFPN from .rec_nrtr_mtb import MTB from .rec_swin import SwinTransformer - support_dict = ['MobileNetV3', 'ResNet', 'ResNetFPN','MTB','SwinTransformer'] + support_dict = ['MobileNetV3', 'ResNet', 'ResNetFPN', 'MTB', 'SwinTransformer'] elif model_type == 'e2e': from .e2e_resnet_vd_pg import ResNet diff --git a/ppocr/modeling/heads/rec_nrtr_optim_head.py b/ppocr/modeling/heads/rec_nrtr_optim_head.py index 1537b0ca..b9a5100a 100644 --- a/ppocr/modeling/heads/rec_nrtr_optim_head.py +++ b/ppocr/modeling/heads/rec_nrtr_optim_head.py @@ -7,11 +7,7 @@ from paddle.nn import LayerList from paddle.nn.initializer import XavierNormal as xavier_uniform_ from paddle.nn import Dropout, Linear, LayerNorm, Conv2D import numpy as np -<<<<<<< HEAD from ppocr.modeling.heads.multiheadAttention import MultiheadAttentionOptim -======= -from ppocr.modeling.backbones.multiheadAttention import MultiheadAttentionOptim ->>>>>>> 9c67a7f... add rec_nrtr from paddle.nn.initializer import Constant as constant_ from paddle.nn.initializer import XavierNormal as xavier_normal_ diff --git a/ppocr/postprocess/rec_postprocess.py b/ppocr/postprocess/rec_postprocess.py index e0f3b740..371e2386 100644 --- a/ppocr/postprocess/rec_postprocess.py +++ b/ppocr/postprocess/rec_postprocess.py @@ -28,7 +28,7 @@ class BaseRecLabelDecode(object): 'ch', 'en', 'EN_symbol', 'french', 'german', 'japan', 'korean', 'it', 'xi', 'pu', 'ru', 'ar', 'ta', 'ug', 'fa', 'ur', 'rs', 'oc', 'rsc', 'bg', 'uk', 'be', 'te', 'ka', 'chinese_cht', 'hi', 'mr', - 'ne', 'EN', 'latin', 'arabic', 'cyrillic', 'devanagari','dict_99' + 'ne', 'EN', 'latin', 'arabic', 'cyrillic', 'devanagari' ] assert character_type in support_character_type, "Only {} are supported now but get {}".format( support_character_type, character_type) diff --git a/ppocr/utils/dict_99.txt b/ppocr/utils/dict_99.txt deleted file mode 100644 index e00863bf..00000000 --- a/ppocr/utils/dict_99.txt +++ /dev/null @@ -1,95 +0,0 @@ -! -" -# -$ -% -& -' -( -) -* -+ -, -- -. -/ -0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -: -; -< -= -> -? -@ -A -B -C -D -E -F -G -H -I -J -K -L -M -N -O -P -Q -R -S -T -U -V -W -X -Y -Z -[ -\ -] -^ -_ -` -a -b -c -d -e -f -g -h -i -j -k -l -m -n -o -p -q -r -s -t -u -v -w -x -y -z -{ -| -} -~ - \ No newline at end of file -- GitLab