metythorn commited on
Commit
88c82fa
·
verified ·
1 Parent(s): b974168

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +25 -11
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, I don’t have a public paper for this model — everything comes from thousands of experiments across different model architectures and datasets.
 
 
 
 
 
 
 
 
15
 
16
- ## Installation
17
- ```python
18
- pip install mer
19
- ```
20
  ## Usage
 
21
  ```python
22
- from mer import Mer
 
 
 
 
 
 
23
 
24
- model = Mer(markdown=True, device='cuda')
25
- result = model.predict("sample_image.png")
26
- print("Predicted text:", result)
 
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
+ ```