Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
```python
|
2 |
+
>>> import easyocr
|
3 |
+
>>> import torch
|
4 |
+
>>> from huggingface_hub import hf_hub_download
|
5 |
+
|
6 |
+
>>> # Initialize default easyocr model
|
7 |
+
>>> reader = easyocr.Reader(['en', 'cs', 'sk', 'pl'])
|
8 |
+
>>> # Download weights of recognition module.
|
9 |
+
>>> model_dir = hf_hub_download(repo_id="fimu-docproc-research/standard_0.4.0_EasyOcrEngine", filename="weights.pth")
|
10 |
+
>>> # Load the weights
|
11 |
+
>>> state_dict = torch.load(model_dir, map_location="cuda")
|
12 |
+
>>> # Load the state dictionary into the model
|
13 |
+
>>> reader.recognizer.load_state_dict(state_dict)
|
14 |
+
|
15 |
+
>>> # Typical usage of easyocr model to get predictions
|
16 |
+
>>> res = reader.readtext(input_img)
|
17 |
+
```
|
18 |
+
|
19 |
+
### Example usage (without GPU):
|
20 |
+
|
21 |
+
```python
|
22 |
+
>>> from collections import OrderedDict
|
23 |
+
|
24 |
+
>>> import easyocr
|
25 |
+
>>> import torch
|
26 |
+
>>> from huggingface_hub import hf_hub_download
|
27 |
+
|
28 |
+
>>> # Initialize default easyocr model
|
29 |
+
>>> reader = easyocr.Reader(['en', 'cs', 'sk', 'pl'], quantize=False, gpu=False)
|
30 |
+
>>> # Download weights of recognition module.
|
31 |
+
>>> model_dir = hf_hub_download(repo_id="fimu-docproc-research/standard_0.4.0_EasyOcrEngine", filename="weights.pth")
|
32 |
+
>>> # Load the weights
|
33 |
+
>>> state_dict = torch.load(model_dir, map_location="cpu")
|
34 |
+
>>> # There is need to remove first 7 characters due to easyocr library
|
35 |
+
>>> new_state_dict = OrderedDict()
|
36 |
+
>>> for key, value in state_dict.items():
|
37 |
+
>>> new_key = key[7:]
|
38 |
+
>>> new_state_dict[new_key] = value
|
39 |
+
|
40 |
+
>>> # Load the state dictionary into the model
|
41 |
+
>>> reader.recognizer.load_state_dict(new_state_dict)
|
42 |
+
|
43 |
+
>>> # Typical usage of easyocr model to get predictions
|
44 |
+
>>> res = reader.readtext(input_img)
|
45 |
+
```
|