Skip to content

Commit

Permalink
rm some useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
yue kun committed Oct 30, 2022
1 parent 8ca7e7e commit d20aa4e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
11 changes: 3 additions & 8 deletions OCR/MGP-STR/test_final.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,7 @@ def validation(model, criterion, evaluation_loader, converter, opt):
if out_pred == gt:
out_n_correct += 1

# calculate confidence score (= multiply of pred_max_prob)
try:
confidence_score = char_preds_max_prob[index].cumprod(dim=0)[-1]
except:
confidence_score = 0 # for empty pred case, when prune after "end of sentence" token ([s])
confidence_score_list.append(confidence_score)
confidence_score_list.append(char_confidence_score)

elif opt.Transformer in ["char-str"]:
attens, char_preds = model(image, is_eval=True) # final
Expand Down Expand Up @@ -393,8 +388,8 @@ def test(opt):
_, accuracy_by_best_model, _, _, _, _, _, _ = validation(
model, criterion, evaluation_loader, converter, opt)
log.write(eval_data_log)
print(f'{accuracy_by_best_model:0.3f}')
log.write(f'{accuracy_by_best_model:0.3f}\n')
print(f'{accuracy_by_best_model[0]:0.3f}')
log.write(f'{accuracy_by_best_model[0]:0.3f}\n')
log.close()

# https://github.com/clovaai/deep-text-recognition-benchmark/issues/125
Expand Down
5 changes: 1 addition & 4 deletions OCR/MGP-STR/train_final_dist.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ def train(opt):

if opt.saved_model != '':
print(f'loading pretrained model from {opt.saved_model}')
if opt.FT:
model.load_state_dict(torch.load(opt.saved_model, map_location='cpu'), strict=True)
else:
model.load_state_dict(torch.load(opt.saved_model, map_location='cpu'), strict=True)
model.load_state_dict(torch.load(opt.saved_model, map_location='cpu'), strict=True)

""" setup loss """
criterion = torch.nn.CrossEntropyLoss(ignore_index=0).to(device) # ignore [GO] token = ignore index 0
Expand Down

0 comments on commit d20aa4e

Please sign in to comment.