Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -9,20 +9,34 @@ tags:
|
|
| 9 |
pipeline_tag: image-to-text
|
| 10 |
---
|
| 11 |
|
| 12 |
-
# Khmer OCR CNN + Transformer
|
| 13 |
|
| 14 |
-
This repository contains a ResNet + Transformer decoder checkpoint for Khmer OCR,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
## Installation
|
| 17 |
-
```python
|
| 18 |
-
pip install mer
|
| 19 |
-
```
|
| 20 |
## Usage
|
|
|
|
| 21 |
```python
|
| 22 |
-
from
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
| 27 |
|
| 28 |
-
|
|
|
|
|
|
|
|
|
| 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="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 |
+
```
|