Download src/linedet/arch_json.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 1.42 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/src/linedet/arch_json.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/src/linedet/arch_json.py
-
curl -L -o arch_json.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/src/linedet/arch_json.py
1.42 kB
| """arch.json: layer list and parameter count per module of every arm, counted from the model objects (CPU, no weights needed).""" | |
| import argparse | |
| import os | |
| from kraken.lib.codec import PytorchCodec | |
| from .common import DATA, LD_OUT, load_json, save_json, utcnow | |
| from .models import build_arm_for_inference, layer_report, n_params | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--codec", default=LD_OUT + "/codec_union.json") | |
| ap.add_argument("--out", default=LD_OUT + "/arch.json") | |
| a = ap.parse_args() | |
| codec = PytorchCodec(load_json(a.codec)["c2l"]) | |
| out = {"created": utcnow(), "codec_classes_including_blank": codec.max_label + 1, | |
| "note": "parameters counted with sum(p.numel()) on the built model objects; 'deployed' is what runs at inference; the NRTR guide head of A1/A2/A1s is used in training only"} | |
| for arm in ("A1", "A2", "A3", "A4", "A1s"): | |
| m = build_arm_for_inference(arm, codec) | |
| rep = m.arch() | |
| entry = {"deployed_params": m.deploy_params(), "layers_deployed": [{"module": n, "class": c, "params": p} for n, c, p in rep["deployed"]]} | |
| if "aux_training_only" in rep: | |
| n, c, p = rep["aux_training_only"] | |
| entry["aux_training_only"] = {"module": "NRTRHead", "params": p} | |
| out[arm] = entry | |
| print(arm, entry["deployed_params"]) | |
| save_json(a.out, out) | |
| if __name__ == "__main__": | |
| main() | |