fix code style

This commit is contained in:
andyjpaddle 2021-09-07 06:09:59 +00:00
parent 8123688a09
commit ae09ef607f

View File

@ -207,7 +207,8 @@ class NRTRLabelDecode(BaseRecLabelDecode):
if text_index[batch_idx][idx] == 3: # end if text_index[batch_idx][idx] == 3: # end
break break
try: try:
char_list.append(self.character[int(text_index[batch_idx][idx])]) char_list.append(self.character[int(text_index[batch_idx][
idx])])
except: except:
continue continue
if text_prob is not None: if text_prob is not None:
@ -219,7 +220,6 @@ class NRTRLabelDecode(BaseRecLabelDecode):
return result_list return result_list
class AttnLabelDecode(BaseRecLabelDecode): class AttnLabelDecode(BaseRecLabelDecode):
""" Convert between text-label and text-index """ """ Convert between text-label and text-index """
@ -257,7 +257,8 @@ class AttnLabelDecode(BaseRecLabelDecode):
if idx > 0 and text_index[batch_idx][idx - 1] == text_index[ if idx > 0 and text_index[batch_idx][idx - 1] == text_index[
batch_idx][idx]: batch_idx][idx]:
continue continue
char_list.append(self.character[int(text_index[batch_idx][idx])]) char_list.append(self.character[int(text_index[batch_idx][
idx])])
if text_prob is not None: if text_prob is not None:
conf_list.append(text_prob[batch_idx][idx]) conf_list.append(text_prob[batch_idx][idx])
else: else:
@ -387,10 +388,9 @@ class SRNLabelDecode(BaseRecLabelDecode):
class TableLabelDecode(object): class TableLabelDecode(object):
""" """ """ """
def __init__(self, def __init__(self, character_dict_path, **kwargs):
character_dict_path, list_character, list_elem = self.load_char_elem_dict(
**kwargs): character_dict_path)
list_character, list_elem = self.load_char_elem_dict(character_dict_path)
list_character = self.add_special_char(list_character) list_character = self.add_special_char(list_character)
list_elem = self.add_special_char(list_elem) list_elem = self.add_special_char(list_elem)
self.dict_character = {} self.dict_character = {}
@ -409,7 +409,8 @@ class TableLabelDecode(object):
list_elem = [] list_elem = []
with open(character_dict_path, "rb") as fin: with open(character_dict_path, "rb") as fin:
lines = fin.readlines() lines = fin.readlines()
substr = lines[0].decode('utf-8').strip("\n").strip("\r\n").split("\t") substr = lines[0].decode('utf-8').strip("\n").strip("\r\n").split(
"\t")
character_num = int(substr[0]) character_num = int(substr[0])
elem_num = int(substr[1]) elem_num = int(substr[1])
for cno in range(1, 1 + character_num): for cno in range(1, 1 + character_num):
@ -435,8 +436,8 @@ class TableLabelDecode(object):
loc_preds = loc_preds.numpy() loc_preds = loc_preds.numpy()
structure_idx = structure_probs.argmax(axis=2) structure_idx = structure_probs.argmax(axis=2)
structure_probs = structure_probs.max(axis=2) structure_probs = structure_probs.max(axis=2)
structure_str, structure_pos, result_score_list, result_elem_idx_list = self.decode(structure_idx, structure_str, structure_pos, result_score_list, result_elem_idx_list = self.decode(
structure_probs, 'elem') structure_idx, structure_probs, 'elem')
res_html_code_list = [] res_html_code_list = []
res_loc_list = [] res_loc_list = []
batch_num = len(structure_str) batch_num = len(structure_str)
@ -451,8 +452,13 @@ class TableLabelDecode(object):
res_loc = np.array(res_loc) res_loc = np.array(res_loc)
res_html_code_list.append(res_html_code) res_html_code_list.append(res_html_code)
res_loc_list.append(res_loc) res_loc_list.append(res_loc)
return {'res_html_code': res_html_code_list, 'res_loc': res_loc_list, 'res_score_list': result_score_list, return {
'res_elem_idx_list': result_elem_idx_list,'structure_str_list':structure_str} 'res_html_code': res_html_code_list,
'res_loc': res_loc_list,
'res_score_list': result_score_list,
'res_elem_idx_list': result_elem_idx_list,
'structure_str_list': structure_str
}
def decode(self, text_index, structure_probs, char_or_elem): def decode(self, text_index, structure_probs, char_or_elem):
"""convert text-label into text-index. """convert text-label into text-index.