Spaces:
Running
Running
Download ocr-training/scripts/export_v24_legacy.py from phucsd/cham-ocr-studio: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/spaces/phucsd/cham-ocr-studio/resolve/main/ocr-training/scripts/export_v24_legacy.py
- Command line
-
hf download hf://spaces/phucsd/cham-ocr-studio/ocr-training/scripts/export_v24_legacy.py
-
curl -L -o export_v24_legacy.py https://huggingface.co/spaces/phucsd/cham-ocr-studio/resolve/main/ocr-training/scripts/export_v24_legacy.py
2.06 kB
| import os | |
| import sys | |
| # NumPy 2.x compatibility monkeypatch | |
| import numpy as np | |
| if not hasattr(np, 'sctypes'): | |
| np.sctypes = {'int': [np.int8, np.int16, np.int32, np.int64], 'uint': [np.uint8, np.uint16, np.uint32, np.uint64], 'float': [np.float16, np.float32, np.float64], 'complex': [np.complex64, np.complex128], 'others': [bool, object, bytes, str]} | |
| if not hasattr(np, 'bool'): np.bool = bool | |
| if not hasattr(np, 'int'): np.int = int | |
| if not hasattr(np, 'float'): np.float = float | |
| if not hasattr(np, 'typeDict'): np.typeDict = {} | |
| import yaml | |
| import paddle | |
| # Add PaddleOCR to sys.path | |
| BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| PADDLEOCR_DIR = os.path.join(BASE_DIR, "ocr-studio", "PaddleOCR") | |
| if PADDLEOCR_DIR not in sys.path: | |
| sys.path.insert(0, PADDLEOCR_DIR) | |
| from ppocr.utils.export_model import export | |
| def run_export(): | |
| config_path = os.path.join(BASE_DIR, "ocr-training", "configs", "rec_cham_v24.yml") | |
| ckpt_path = os.path.join(BASE_DIR, "ocr-training", "output", "v24", "extracted_v24", "best_checkpoint", "best_accuracy") | |
| save_dir = os.path.join(BASE_DIR, "ocr-studio", "data", "output", "rec_cham_inference_v24") | |
| dict_path = os.path.join(BASE_DIR, "ocr-training", "data", "cham_dict_v24.txt") | |
| print(f"Loading config from: {config_path}") | |
| with open(config_path, 'r', encoding='utf-8') as f: | |
| config = yaml.safe_load(f) | |
| config["Global"]["pretrained_model"] = ckpt_path | |
| config["Global"]["checkpoints"] = None | |
| config["Global"]["character_dict_path"] = dict_path | |
| config["Global"]["save_inference_dir"] = save_dir | |
| config["Global"]["export_with_pir"] = False # Force legacy .pdmodel format via OldIrGuard! | |
| print(f"Exporting model with export_with_pir=False to {save_dir}...") | |
| export(config) | |
| print("\n✅ Export completed successfully! Listing files in save_dir:") | |
| for f in os.listdir(save_dir): | |
| fp = os.path.join(save_dir, f) | |
| print(f" - {f}: {os.path.getsize(fp):,} bytes") | |
| if __name__ == "__main__": | |
| run_export() | |