Download code/scripts/compute_scaling.py from reneeice/sparse-adversarial-research-archive: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/datasets/reneeice/sparse-adversarial-research-archive/resolve/main/code/scripts/compute_scaling.py
- Command line
-
hf download hf://datasets/reneeice/sparse-adversarial-research-archive/code/scripts/compute_scaling.py
-
curl -L -o compute_scaling.py https://huggingface.co/datasets/reneeice/sparse-adversarial-research-archive/resolve/main/code/scripts/compute_scaling.py
1.65 kB
| """Does converge-prune keep tightening the support with more compute? Test 20/40/70s on high-gap | |
| rows. If density keeps dropping -> speeding the inner loop (skip SSIM in search) buys real gains.""" | |
| from __future__ import annotations | |
| import sys, time, base64, io | |
| from pathlib import Path | |
| REPO_ROOT = Path(__file__).resolve().parents[1] | |
| if str(REPO_ROOT) not in sys.path: sys.path.insert(0, str(REPO_ROOT)) | |
| import torch | |
| from miner_lib.victim import VictimModel | |
| from miner_lib.config import AttackConfig | |
| from miner_lib.converge_prune_attack import run_converge_prune_attack | |
| from perturbnet.imagenet100_bootstrap import load_imagenet100 | |
| from perturbnet.image_io import decode_image_b64 | |
| def pil_b64(img): | |
| b=io.BytesIO(); img.convert("RGB").save(b, format="PNG"); return base64.b64encode(b.getvalue()).decode() | |
| def main(): | |
| rows=[int(a) for a in sys.argv[1:]] or [96196,18414,18726,120577] | |
| ds=load_imagenet100(split="train") | |
| victim=VictimModel(device="cuda" if torch.cuda.is_available() else "cpu") | |
| print(f"{'row':<9}{'budget':<8}{'score':<9}{'margin':<8}{'dens%':<8}{'rmse'}") | |
| for row in rows: | |
| if row>=ds.num_rows: continue | |
| x=decode_image_b64(pil_b64(ds[row]["image"])).to(victim.device) | |
| _,_,cl=victim.evaluate((x.clamp(0,1)*255).round().long().float()/255,0); ti=int(cl.argmax().item()) | |
| for bud in [20.0,40.0,70.0]: | |
| cfg=AttackConfig(time_budget_seconds=bud) | |
| r=run_converge_prune_attack(victim,x,ti,cfg,deadline=time.time()+bud) | |
| print(f"{row:<9}{bud:<8.0f}{r.score:<9.4f}{r.margin:<8.2f}{r.density*100:<8.1f}{r.rmse:.6f}",flush=True) | |
| if __name__=="__main__": main() | |