From e760df4b1e59f98ee98b084746e3cf781e25cc9e Mon Sep 17 00:00:00 2001 From: andyjpaddle Date: Wed, 13 Oct 2021 11:40:38 +0000 Subject: [PATCH 1/3] add sar dict --- ppocr/losses/rec_sar_loss.py | 9 ++-- ppocr/utils/dict90.txt | 90 ++++++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 ppocr/utils/dict90.txt diff --git a/ppocr/losses/rec_sar_loss.py b/ppocr/losses/rec_sar_loss.py index 9e1c6495fb..c8bd8bb0ca 100644 --- a/ppocr/losses/rec_sar_loss.py +++ b/ppocr/losses/rec_sar_loss.py @@ -9,11 +9,14 @@ from paddle import nn class SARLoss(nn.Layer): def __init__(self, **kwargs): super(SARLoss, self).__init__() - self.loss_func = paddle.nn.loss.CrossEntropyLoss(reduction="mean", ignore_index=96) + self.loss_func = paddle.nn.loss.CrossEntropyLoss( + reduction="mean", ignore_index=92) def forward(self, predicts, batch): - predict = predicts[:, :-1, :] # ignore last index of outputs to be in same seq_len with targets - label = batch[1].astype("int64")[:, 1:] # ignore first index of target in loss calculation + predict = predicts[:, : + -1, :] # ignore last index of outputs to be in same seq_len with targets + label = batch[1].astype( + "int64")[:, 1:] # ignore first index of target in loss calculation batch_size, num_steps, num_classes = predict.shape[0], predict.shape[ 1], predict.shape[2] assert len(label.shape) == len(list(predict.shape)) - 1, \ diff --git a/ppocr/utils/dict90.txt b/ppocr/utils/dict90.txt new file mode 100644 index 0000000000..a945ae9c52 --- /dev/null +++ b/ppocr/utils/dict90.txt @@ -0,0 +1,90 @@ +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 From 283b46c46664a76021c0e79703adbcfe6ac40e31 Mon Sep 17 00:00:00 2001 From: andyjpaddle Date: Thu, 14 Oct 2021 01:42:34 +0000 Subject: [PATCH 2/3] update sar dict --- configs/rec/rec_r31_sar.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/rec/rec_r31_sar.yml b/configs/rec/rec_r31_sar.yml index 41609fdf28..f6fdc41c7c 100644 --- a/configs/rec/rec_r31_sar.yml +++ b/configs/rec/rec_r31_sar.yml @@ -15,7 +15,7 @@ Global: infer_img: # for data or label process character_dict_path: ppocr/utils/dict90.txt - character_type: EN_symbol + character_type: ch max_text_length: 30 infer_mode: False use_space_char: False From 60eb741a133cb334be70010e2aa774f9eaa6c89c Mon Sep 17 00:00:00 2001 From: andyjpaddle Date: Thu, 14 Oct 2021 03:01:19 +0000 Subject: [PATCH 3/3] add sar dict --- configs/rec/rec_r31_sar.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configs/rec/rec_r31_sar.yml b/configs/rec/rec_r31_sar.yml index f6fdc41c7c..41609fdf28 100644 --- a/configs/rec/rec_r31_sar.yml +++ b/configs/rec/rec_r31_sar.yml @@ -15,7 +15,7 @@ Global: infer_img: # for data or label process character_dict_path: ppocr/utils/dict90.txt - character_type: ch + character_type: EN_symbol max_text_length: 30 infer_mode: False use_space_char: False