eval with alphanumeric and case sensitive setting

This commit is contained in:
Baek JeongHun 2020-02-25 11:06:34 +00:00
parent 49942e5dc0
commit 5b132b932d
2 changed files with 15 additions and 6 deletions

11
test.py
View File

@ -2,6 +2,7 @@ import os
import time import time
import string import string
import argparse import argparse
import re
import torch import torch
import torch.backends.cudnn as cudnn import torch.backends.cudnn as cudnn
@ -133,6 +134,14 @@ def validation(model, criterion, evaluation_loader, converter, opt):
pred = pred[:pred_EOS] # prune after "end of sentence" token ([s]) pred = pred[:pred_EOS] # prune after "end of sentence" token ([s])
pred_max_prob = pred_max_prob[:pred_EOS] pred_max_prob = pred_max_prob[:pred_EOS]
# To evaluate the model with 'alphanumeric and case insensitve setting'
if opt.sensitive and opt.data_filtering_off:
pred = pred.lower()
gt = gt.lower()
alphanumeric_case_insensitve = '0123456789abcdefghijklmnopqrstuvwxyz'
out_of_alphanumeric_case_insensitve = f'[^{alphanumeric_case_insensitve}]'
pred = re.sub(out_of_alphanumeric_case_insensitve, '', pred)
if pred == gt: if pred == gt:
n_correct += 1 n_correct += 1
@ -146,7 +155,7 @@ def validation(model, criterion, evaluation_loader, converter, opt):
''' '''
# ICDAR2019 Normalized Edit Distance # ICDAR2019 Normalized Edit Distance
if len(gt) == 0 or len(pred) ==0: if len(gt) == 0 or len(pred) == 0:
norm_ED += 0 norm_ED += 0
elif len(gt) > len(pred): elif len(gt) > len(pred):
norm_ED += 1 - edit_distance(pred, gt) / len(gt) norm_ED += 1 - edit_distance(pred, gt) / len(gt)