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

add nrtr dml distill loss #9968

Merged
merged 26 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a201c3f
support min_area_rect crop
LDOUBLEV Oct 27, 2022
e53b2c5
add check_install
LDOUBLEV Nov 1, 2022
036f656
fix requirement.txt
LDOUBLEV Nov 1, 2022
d72f1ed
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV Nov 1, 2022
77eb065
fix check_install
LDOUBLEV Nov 2, 2022
501a677
add lanms-neo for drrg
LDOUBLEV Nov 2, 2022
1a79bfb
fix
LDOUBLEV Nov 4, 2022
bc7c761
fix doc
LDOUBLEV Nov 9, 2022
c478c59
fix
LDOUBLEV Dec 6, 2022
88ca1f1
fix conflict
LDOUBLEV Dec 8, 2022
e2a5cf9
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV Jan 30, 2023
ae41145
support set gpu_id when inference
LDOUBLEV Jan 30, 2023
92507b6
fix #8855
LDOUBLEV Jan 30, 2023
9b1b8c7
fix #8855
LDOUBLEV Jan 30, 2023
fbc1bc8
opt slim doc
LDOUBLEV Jan 31, 2023
9d71100
fix doc bug
LDOUBLEV Jan 31, 2023
a7c1cd4
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV Jan 31, 2023
204197e
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV Feb 16, 2023
b344e39
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV May 9, 2023
4c4e254
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV May 11, 2023
79533ff
add v4_rec_distill config
LDOUBLEV May 11, 2023
4e16b5d
delete debug
LDOUBLEV May 11, 2023
96244db
fix comment
LDOUBLEV May 15, 2023
6aefd22
fix comment
LDOUBLEV May 15, 2023
eb9b7c3
add dml nrtr distill loss
LDOUBLEV May 17, 2023
db89495
fix conflict
LDOUBLEV May 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix comment
  • Loading branch information
LDOUBLEV committed May 15, 2023
commit 6aefd22aa612e3fe0decc922591fdd19e69e0765
21 changes: 5 additions & 16 deletions configs/rec/PP-OCRv4/ch_PP-OCRv4_rec_distill.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,9 @@ Train:
- DecodeImage:
img_mode: BGR
channel_first: false
- RecAug: null
- RecAug:
- MultiLabelEncode:
gtc_encode: NRTRLabelEncode
- RecResizeImg:
image_shape:
- 3
- 48
- 320
- KeepKeys:
keep_keys:
- image
Expand All @@ -218,15 +213,9 @@ Eval:
img_mode: BGR
channel_first: false
- MultiLabelEncode:
max_text_length: 600
character_dict_path: ppocr/utils/ppocr_keys_v1.txt
use_space_char: true
gtc_encode: NRTRLabelEncode
- RecResizeImg:
image_shape:
- 3
- 48
- 320
eval_mode: true
image_shape: [3, 48, 320]
- KeepKeys:
keep_keys:
- image
Expand All @@ -237,6 +226,6 @@ Eval:
loader:
shuffle: false
drop_last: false
batch_size_per_card: 1
num_workers: 16
batch_size_per_card: 128
num_workers: 4
profiler_options: null
11 changes: 2 additions & 9 deletions ppocr/losses/distillation_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,6 @@ def _slice_out(self, outs):

def forward(self, predicts, batch):
loss_dict = dict()
# print([x.shape for x in batch])
# print("batch[1]: ", batch[1][0].tolist())
# print("batch[2]: ", batch[2][0].tolist())
# print("batch[3]: ", batch[3])

for idx, pair in enumerate(self.model_name_pairs):
out1 = predicts[pair[0]]
Expand All @@ -312,15 +308,13 @@ def forward(self, predicts, batch):
max_len = batch[3].max()
tgt = batch[2][:, 1:2 +
max_len] # [batch_size, max_len + 1]
# print("targets: ", tgt[0].tolist())

tgt = tgt.reshape([-1]) # batch_size * (max_len + 1)
# print("predicts: ", paddle.argmax(out2[self.dis_head][0], axis=-1).tolist())
# print("predicts: ", out2[self.dis_head][0].max(axis=-1).tolist())
non_pad_mask = paddle.not_equal(
tgt, paddle.zeros(
tgt.shape,
dtype=tgt.dtype)) # batch_size * (max_len + 1)
# print("batch", out1[self.dis_head].shape)

loss = super().forward(
out1[self.dis_head], out2[self.dis_head], tgt,
non_pad_mask) # [batch_size, max_len + 1, num_char]
Expand Down Expand Up @@ -752,7 +746,6 @@ def forward(self, logits_student, logits_teacher, targets, mask=None):

gt_mask = self.multi_label_mask(targets)
other_mask = paddle.ones_like(gt_mask) - gt_mask
# other_mask = 1 - gt_mask

pred_student = F.softmax(logits_student / self.temperature, axis=-1)
pred_teacher = F.softmax(logits_teacher / self.temperature, axis=-1)
Expand Down