MCPcopy Create free account
hub / github.com/Topdu/OpenOCR / __call__

Method __call__

openrec/preprocess/cppd_label_encode.py:30–82  ·  view source on GitHub ↗
(self, data)

Source from the content-addressed store, hash-verified

28 self.pos_len = pos_len
29
30 def __call__(self, data):
31 text = data['label']
32 if self.ch:
33 text, text_node_index, text_node_num = self.encodech(text)
34 if text is None:
35 return None
36 if len(text) > self.max_text_len:
37 return None
38 data['length'] = np.array(len(text))
39 # text.insert(0, 0)
40 if self.pos_len:
41 text_pos_node = [i_ for i_ in range(len(text), -1, -1)
42 ] + [100] * (self.max_text_len - len(text))
43 else:
44 text_pos_node = [1] * (len(text) + 1) + [0] * (
45 self.max_text_len - len(text))
46
47 text.append(0)
48 text + [0] * (self.max_text_len - len(text))
49
50 text = text + [self.ignore_index
51 ] * (self.max_text_len + 1 - len(text))
52
53 data['label'] = np.array(text)
54 data['label_node'] = np.array(text_node_num + text_pos_node)
55 data['label_index'] = np.array(text_node_index)
56 # data['label_ctc'] = np.array(ctc_text)
57 return data
58 else:
59 text, text_char_node, ch_order = self.encode(text)
60
61 if text is None:
62 return None
63 if len(text) > self.max_text_len:
64 return None
65 data['length'] = np.array(len(text))
66 # text.insert(0, 0)
67 if self.pos_len:
68 text_pos_node = [i_ for i_ in range(len(text), -1, -1)
69 ] + [100] * (self.max_text_len - len(text))
70 else:
71 text_pos_node = [1] * (len(text) + 1) + [0] * (
72 self.max_text_len - len(text))
73
74 text.append(0)
75
76 text = text + [self.ignore_index
77 ] * (self.max_text_len + 1 - len(text))
78 data['label'] = np.array(text)
79 data['label_node'] = np.array(text_char_node + text_pos_node)
80 data['label_order'] = np.array(ch_order)
81
82 return data
83
84 def add_special_char(self, dict_character):
85 if self.use_sos:

Callers

nothing calls this directly

Calls 2

encodechMethod · 0.95
encodeMethod · 0.95

Tested by

no test coverage detected