Views
No views yet
1>>> import easyocr
2>>> import torch
3>>> from huggingface_hub import hf_hub_download
4
5>>> # Initialize default easyocr model
6>>> reader = easyocr.Reader(['en', 'cs', 'sk', 'pl'])
7>>> # Download weights of recognition module.
8>>> model_dir = hf_hub_download(repo_id="fimu-docproc-research/standard_0.4.0_EasyOcrEngine", filename="weights.pth")
9>>> # Load the weights
10>>> state_dict = torch.load(model_dir, map_location="cuda")
11>>> # Load the state dictionary into the model
12>>> reader.recognizer.load_state_dict(state_dict)
13
14>>> # Typical usage of easyocr model to get predictions
15>>> res = reader.readtext(input_img)1>>> from collections import OrderedDict
2
3>>> import easyocr
4>>> import torch
5>>> from huggingface_hub import hf_hub_download
6
7>>> # Initialize default easyocr model
8>>> reader = easyocr.Reader(['en', 'cs', 'sk', 'pl'], quantize=False, gpu=False)
9>>> # Download weights of recognition module.
10>>> model_dir = hf_hub_download(repo_id="fimu-docproc-research/standard_0.4.0_EasyOcrEngine", filename="weights.pth")
11>>> # Load the weights
12>>> state_dict = torch.load(model_dir, map_location="cpu")
13>>> # There is need to remove first 7 characters due to easyocr library
14>>> new_state_dict = OrderedDict()
15>>> for key, value in state_dict.items():
16>>> new_key = key[7:]
17>>> new_state_dict[new_key] = value
18
19>>> # Load the state dictionary into the model
20>>> reader.recognizer.load_state_dict(new_state_dict)
21
22>>> # Typical usage of easyocr model to get predictions
23>>> res = reader.readtext(input_img)