Download scripts/r5_release/rc1_prep_det.py from treoa/turkic-ocr-code: direct link, hf CLI and curl.
- Browser
- Download file 2.31 kB
-
https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_release/rc1_prep_det.py
- Command line
-
hf download hf://treoa/turkic-ocr-code/scripts/r5_release/rc1_prep_det.py
-
curl -L -o rc1_prep_det.py https://huggingface.co/treoa/turkic-ocr-code/resolve/main/scripts/r5_release/rc1_prep_det.py
2.31 kB
| """rc1 prep, detector: what the stage-2 checkpoint best.pt says about itself, and its parameter count. | |
| Run with CODE/.venv_kraken/bin/python -I. Loads the checkpoint with ultralytics (the pickle is our own training output), prints the | |
| metadata keys it carries (epoch, best fitness, version, licence line, whether the training arguments hold cluster paths), counts parameters. | |
| usage: rc1_prep_det.py WEIGHTS REPORT_JSON | |
| """ | |
| import json | |
| import os | |
| import sys | |
| import tempfile | |
| os.environ.setdefault("YOLO_OFFLINE", "1") | |
| os.environ.setdefault("YOLO_CONFIG_DIR", os.path.join(tempfile.gettempdir(), "ultralytics_cfg_rc1_prep")) | |
| import torch # noqa: E402 | |
| import ultralytics # noqa: E402 | |
| from ultralytics import YOLO # noqa: E402 | |
| def main(): | |
| w, rep = sys.argv[1:3] | |
| m = YOLO(w) | |
| ck = m.ckpt if isinstance(getattr(m, "ckpt", None), dict) else {} | |
| out = {"ultralytics": ultralytics.__version__, "torch": torch.__version__, "ckpt_keys": sorted(ck.keys()), | |
| "task": getattr(m, "task", None), "names": getattr(m.model, "names", None)} | |
| for k in ("epoch", "best_fitness", "date", "version", "license", "docs"): | |
| if k in ck: | |
| out["ckpt_" + k] = ck[k] | |
| ta = ck.get("train_args") or {} | |
| out["train_args_keys_n"] = len(ta) | |
| out["train_args_model"] = str(ta.get("model")) | |
| out["train_args_data"] = str(ta.get("data")) | |
| out["train_args_epochs"] = ta.get("epochs") | |
| out["train_args_time"] = ta.get("time") | |
| out["train_args_imgsz"] = ta.get("imgsz") | |
| out["train_args_hold_datahub_paths"] = sorted(k for k, v in ta.items() if isinstance(v, str) and ("/datahub" in v or "/shared/home" in v)) | |
| seen, n = set(), 0 | |
| for p in m.model.parameters(): | |
| if id(p) not in seen: | |
| seen.add(id(p)) | |
| n += p.numel() | |
| out["parameters"] = n | |
| out["dtype_first_param"] = str(next(m.model.parameters()).dtype) | |
| tm = ck.get("train_metrics") or ck.get("train_results") | |
| out["train_metrics_in_ckpt"] = tm if isinstance(tm, dict) else None | |
| with open(rep, "w", encoding="utf-8") as f: | |
| json.dump(out, f, indent=1, ensure_ascii=False, default=str) | |
| print(json.dumps({k: out[k] for k in ("parameters", "ckpt_epoch", "ckpt_best_fitness", "train_args_hold_datahub_paths")}, default=str)) | |
| if __name__ == "__main__": | |
| main() | |