Download example.py from LocalDoc/azerbaijani-ocr-crnn: direct link, hf CLI and curl.
- Browser
- Download file 406 Bytes
-
https://huggingface.co/LocalDoc/azerbaijani-ocr-crnn/resolve/main/example.py
- Command line
-
hf download hf://LocalDoc/azerbaijani-ocr-crnn/example.py
-
curl -L -o example.py https://huggingface.co/LocalDoc/azerbaijani-ocr-crnn/resolve/main/example.py
406 Bytes
| """Minimal usage example.""" | |
| import torch | |
| from PIL import Image | |
| from huggingface_hub import hf_hub_download | |
| from modeling import load, preprocess, ctc_greedy | |
| path = hf_hub_download("LocalDoc/azerbaijani-ocr-crnn", "model.pt") | |
| model, itos = load(path) | |
| img = Image.open("line.png") # crop of ONE text line | |
| with torch.no_grad(): | |
| logits = model(preprocess(img)) | |
| print(ctc_greedy(logits, itos)) | |