Datasets:
Download scripts/run_model_matrix.py from ImtiazulIslam/bdfd9-v3-fabric-defect-classification: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/datasets/ImtiazulIslam/bdfd9-v3-fabric-defect-classification/resolve/main/scripts/run_model_matrix.py
- Command line
-
hf download hf://datasets/ImtiazulIslam/bdfd9-v3-fabric-defect-classification/scripts/run_model_matrix.py
-
curl -L -o run_model_matrix.py https://huggingface.co/datasets/ImtiazulIslam/bdfd9-v3-fabric-defect-classification/resolve/main/scripts/run_model_matrix.py
2.37 kB
| #!/usr/bin/env python3 | |
| """Run a validation-only multi-model/multi-seed experiment matrix; never evaluates test.""" | |
| from pathlib import Path | |
| import argparse,subprocess,sys,json,time | |
| ROOT=Path(__file__).resolve().parents[1] | |
| MODELS=["small_cnn","resnet18","mobilenet_v3_small","efficientnet_b0","shufflenet_v2"] | |
| def main(): | |
| ap=argparse.ArgumentParser() | |
| ap.add_argument("--epochs",type=int,default=10) | |
| ap.add_argument("--seeds",nargs="+",type=int,default=[2026,2027,2028,2029,2030]) | |
| ap.add_argument("--models",nargs="+",default=MODELS,choices=MODELS) | |
| ap.add_argument("--batch-size",type=int,default=64) | |
| ap.add_argument("--workers",type=int,default=2) | |
| ap.add_argument("--size",type=int,default=192) | |
| ap.add_argument("--resume",action="store_true") | |
| a=ap.parse_args() | |
| ex=ROOT/"dataset_audit"/"cross_split_exclusions.csv" | |
| if not ex.is_file():raise SystemExit(f"Missing leakage-control file: {ex}") | |
| exp=ROOT/"experiments";logs=exp/"logs";logs.mkdir(parents=True,exist_ok=True) | |
| config={"models":a.models,"seeds":a.seeds,"epochs":a.epochs,"batch_size":a.batch_size,"workers":a.workers,"size":a.size,"exclude_csv":str(ex)} | |
| (exp/"matrix_config.json").write_text(json.dumps(config,indent=2)) | |
| total=len(a.models)*len(a.seeds);done=0 | |
| for seed in a.seeds: | |
| for model in a.models: | |
| name=f"{model}_seed{seed}_e{a.epochs}_s{a.size}_b{a.batch_size}_w{a.workers}_leakage_controlled" | |
| result=exp/name/"results.json" | |
| if a.resume and result.is_file(): | |
| print(f"SKIP existing {name}",flush=True);done+=1;continue | |
| cmd=[sys.executable,str(ROOT/"scripts"/"train_multilabel.py"),"--model",model,"--epochs",str(a.epochs),"--seed",str(seed),"--batch-size",str(a.batch_size),"--workers",str(a.workers),"--size",str(a.size),"--run-name",name,"--exclude-csv",str(ex)] | |
| print(f"START {done+1}/{total}: {name}",flush=True) | |
| start=time.time() | |
| with (logs/f"{name}.log").open("w") as log: | |
| rc=subprocess.run(cmd,cwd=ROOT,stdout=log,stderr=subprocess.STDOUT).returncode | |
| done+=1 | |
| if rc: | |
| print(f"FAILED {name} exit={rc}; inspect {logs/name}.log; stopping matrix for safe resume",flush=True) | |
| raise SystemExit(rc) | |
| print(f"FINISHED {name} in {(time.time()-start)/60:.1f} min",flush=True) | |
| print("MATRIX COMPLETE",flush=True) | |
| subprocess.run([sys.executable,str(ROOT/"scripts"/"summarize_validation_runs.py")],cwd=ROOT,check=True) | |
| if __name__=="__main__":main() | |