Download scripts/archive_run.py from XenderYang/CSIGv3_train_script: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/XenderYang/CSIGv3_train_script/resolve/main/scripts/archive_run.py
- Command line
-
hf download hf://XenderYang/CSIGv3_train_script/scripts/archive_run.py
-
curl -L -o archive_run.py https://huggingface.co/XenderYang/CSIGv3_train_script/resolve/main/scripts/archive_run.py
1.57 kB
| #!/usr/bin/env python | |
| """归档: 把 logs/<run> 与权重副本整理到 archive/<date>_<name>/, 生成 summary.txt | |
| 用法: python scripts/archive_run.py --name s2_best --src_log logs/s2 --weights weight/s2/net_params_*.pkl | |
| """ | |
| import argparse, os, shutil, json, glob, datetime | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--name", required=True) | |
| ap.add_argument("--src_log", default="logs") | |
| ap.add_argument("--weights", nargs="*", default=[]) | |
| ap.add_argument("--eval_json", default="", help="eval_val.py 输出") | |
| args = ap.parse_args() | |
| dst = os.path.join("archive", f"{datetime.date.today().isoformat()}_{args.name}") | |
| os.makedirs(dst, exist_ok=True) | |
| if os.path.isdir(args.src_log): | |
| shutil.copytree(args.src_log, os.path.join(dst, "log"), dirs_exist_ok=True) | |
| wd = os.path.join(dst, "weights"); os.makedirs(wd, exist_ok=True) | |
| for pat in args.weights: | |
| for f in glob.glob(pat): | |
| shutil.copy2(f, os.path.join(wd, os.path.basename(f))) | |
| summary = {"name": args.name, "date": datetime.date.today().isoformat(), "weights": [os.path.basename(f) for pat in args.weights for f in glob.glob(pat)]} | |
| if args.eval_json and os.path.exists(args.eval_json): | |
| with open(args.eval_json, encoding="utf-8") as fh: | |
| summary["eval_mean"] = json.load(fh).get("mean") | |
| with open(os.path.join(dst, "summary.txt"), "w", encoding="utf-8") as fh: | |
| fh.write(json.dumps(summary, ensure_ascii=False, indent=1)) | |
| print("archived to", dst) | |
| if __name__ == "__main__": | |
| main() | |