Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- km
|
| 4 |
+
license: apache-2.0
|
| 5 |
+
tags:
|
| 6 |
+
- ocr
|
| 7 |
+
- transformer
|
| 8 |
+
- vision
|
| 9 |
+
pipeline_tag: image-to-text
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Khmer OCR CNN + Transformer (ONNX)
|
| 13 |
+
|
| 14 |
+
This repository contains a ResNet + Transformer decoder checkpoint for Khmer OCR,
|
| 15 |
+
the exported ONNX graph, the serialized `config.json` (vocab + hyperparameters),
|
| 16 |
+
and the standalone `inference_onnx.py` helper.
|
| 17 |
+
|
| 18 |
+
## Files
|
| 19 |
+
|
| 20 |
+
- `khmer_ocr.onnx` – ONNX model
|
| 21 |
+
- `config.json` – hyperparameters plus serialized vocabulary
|
| 22 |
+
- `inference_onnx.py` and `model.py` – inference helper and architecture
|
| 23 |
+
|
| 24 |
+
## Usage
|
| 25 |
+
|
| 26 |
+
```python
|
| 27 |
+
from huggingface_hub import hf_hub_download
|
| 28 |
+
import importlib.util
|
| 29 |
+
|
| 30 |
+
repo_id = "metythorn/ocr-stn-cnn-transformer-base"
|
| 31 |
+
onnx_path = hf_hub_download(repo_id=repo_id, filename="khmer_ocr.onnx")
|
| 32 |
+
config_path = hf_hub_download(repo_id=repo_id, filename="config.json")
|
| 33 |
+
inference_path = hf_hub_download(repo_id=repo_id, filename="inference_onnx.py")
|
| 34 |
+
|
| 35 |
+
spec = importlib.util.spec_from_file_location("khmer_ocr_infer", inference_path)
|
| 36 |
+
module = importlib.util.module_from_spec(spec)
|
| 37 |
+
spec.loader.exec_module(module)
|
| 38 |
+
ONNXPredictor = module.ONNXPredictor
|
| 39 |
+
|
| 40 |
+
predictor = ONNXPredictor(model_path=onnx_path, config_path=config_path)
|
| 41 |
+
print(predictor.predict("path/to/image.jpg"))
|
| 42 |
+
```
|