(recog_network, network_params, character,\
separator_list, dict_list, model_path,\
device = 'cpu', quantize = True)
| 151 | return result |
| 152 | |
| 153 | def get_recognizer(recog_network, network_params, character,\ |
| 154 | separator_list, dict_list, model_path,\ |
| 155 | device = 'cpu', quantize = True): |
| 156 | |
| 157 | converter = CTCLabelConverter(character, separator_list, dict_list) |
| 158 | num_class = len(converter.character) |
| 159 | |
| 160 | if recog_network == 'generation1': |
| 161 | model_pkg = importlib.import_module("easyocr.model.model") |
| 162 | elif recog_network == 'generation2': |
| 163 | model_pkg = importlib.import_module("easyocr.model.vgg_model") |
| 164 | else: |
| 165 | model_pkg = importlib.import_module(recog_network) |
| 166 | model = model_pkg.Model(num_class=num_class, **network_params) |
| 167 | |
| 168 | if device == 'cpu': |
| 169 | state_dict = torch.load(model_path, map_location=device, weights_only=False) |
| 170 | new_state_dict = OrderedDict() |
| 171 | for key, value in state_dict.items(): |
| 172 | new_key = key[7:] |
| 173 | new_state_dict[new_key] = value |
| 174 | model.load_state_dict(new_state_dict) |
| 175 | if quantize: |
| 176 | try: |
| 177 | torch.quantization.quantize_dynamic(model, dtype=torch.qint8, inplace=True) |
| 178 | except: |
| 179 | pass |
| 180 | else: |
| 181 | model = torch.nn.DataParallel(model).to(device) |
| 182 | model.load_state_dict(torch.load(model_path, map_location=device, weights_only=False)) |
| 183 | |
| 184 | return model, converter |
| 185 | |
| 186 | def get_text(character, imgH, imgW, recognizer, converter, image_list,\ |
| 187 | ignore_char = '',decoder = 'greedy', beamWidth =5, batch_size=1, contrast_ths=0.1,\ |
no test coverage detected
searching dependent graphs…