"""Generate README.md (dataset card + viewer configs) from out/manifests/*.json.""" import json from pathlib import Path ROOT = Path(__file__).parent / "out" DATASETS = [ # (config name, display, domain, granularity, upstream url, upstream license) ("caltech101", "Caltech-101", "objects", "coarse", "https://data.caltech.edu/records/mzrjq-6wc02", "CC BY 4.0"), ("fgvc-aircraft-2013b", "FGVC-Aircraft (2013b)", "aircraft", "fine", "https://www.robots.ox.ac.uk/~vgg/data/fgvc-aircraft/", "non-commercial research use only"), ("flowers-102", "Oxford Flowers-102", "flowers", "fine", "https://www.robots.ox.ac.uk/~vgg/data/flowers/102/", "see upstream terms"), ("oxford-iiit-pet", "Oxford-IIIT Pet", "pets", "fine", "https://www.robots.ox.ac.uk/~vgg/data/pets/", "CC BY-SA 4.0"), ("stanford_cars", "Stanford Cars", "cars", "fine", "https://ai.stanford.edu/~jkrause/cars/car_dataset.html", "see upstream terms (research use)"), ("uc-merced-land-use-dataset", "UC Merced Land Use", "satellite", "coarse", "http://weegee.vision.ucmerced.edu/datasets/landuse.html", "USGS public-domain imagery"), ] SURR = [ # (prefix, display, checkpoint) ("clip_vitb16", "CLIP ViT-B/16", "open_clip `ViT-B-16` / `laion2b_s34b_b88k`"), ("clip_vith14", "CLIP ViT-H/14", "open_clip `ViT-H-14` / `laion2b_s32b_b79k`"), ("metaclip_vith14", "MetaCLIP ViT-H/14", "open_clip `ViT-H-14-quickgelu` / `metaclip_fullcc`"), ("siglip2_so400m", "SigLIP2 SO400M", "`google/siglip2-so400m-patch14-384`"), ("siglip2_base", "SigLIP2 base", "`google/siglip2-base-patch16-224`"), ] THREATS = [("l1_75", "ℓ1", "75"), ("l1_300", "ℓ1", "300"), ("l2_2", "ℓ2", "2"), ("l2_8", "ℓ2", "8"), ("linf_4", "ℓ∞", "4/255"), ("linf_8", "ℓ∞", "8/255"), ("linf_30", "ℓ∞", "30/255")] ORDER = ["train", "validation", "test", "common", "random_linf_30"] + \ [f"{s}_{t}" for s, _, _ in SURR for t, _, _ in THREATS] man = {d[0]: json.loads((ROOT / "manifests" / f"{d[0]}.json").read_text()) for d in DATASETS} # ── YAML header ────────────────────────────────────────────────────────────── y = ["---", "license: cc-by-nc-4.0", "language:", "- en", "pretty_name: RobustGenBench", "size_categories:", "- 100K (clean + model-independent splits) and - # (one split per budget). The Dataset Viewer caps the number of splits per config. BASE_SPLITS = ["train", "validation", "test", "common", "random_linf_30"] for cfg, *_rest in DATASETS: y += [f"- config_name: {cfg}"] + ([" default: true"] if cfg == "caltech101" else []) + [" data_files:"] for sp in BASE_SPLITS: y += [f" - split: {sp}", f" path: data/{cfg}/{sp}-*.parquet"] for s, _, _ in SURR: for cfg, *_rest in DATASETS: threats = [t for t, _, _ in THREATS if f"{s}_{t}" in man[cfg]["splits"]] if not threats: continue y += [f"- config_name: {cfg}-{s}", " data_files:"] for t in threats: y += [f" - split: {t}", f" path: data/{cfg}/{s}_{t}-*.parquet"] y.append("---") # ── Coverage table ─────────────────────────────────────────────────────────── def mark(cfg, sp): return "✓" if sp in man[cfg]["splits"] else "–" cov = ["| Surrogate | Split | " + " | ".join(d[1] for d in DATASETS) + " |", "|---|---|" + "---|" * len(DATASETS)] for s, disp, _ in SURR: for t, n, e in THREATS: sp = f"{s}_{t}" if any(sp in man[d[0]]["splits"] for d in DATASETS): cov.append(f"| {disp} | `{t}` | " + " | ".join(mark(d[0], sp) for d in DATASETS) + " |") ds_rows = "\n".join( f"| `{c}` | {disp} | {dom} | {gr} | {man[c]['num_classes']} | " f"{man[c]['splits']['train']['num_rows']:,} | {man[c]['splits']['validation']['num_rows']:,} | " f"{man[c]['splits']['test']['num_rows']:,} |" for c, disp, dom, gr, *_ in DATASETS) lic_rows = "\n".join(f"| {disp} | [{u}]({u}) | {lic} |" for c, disp, _, _, u, lic in DATASETS) surr_rows = "\n".join(f"| `{p}` | {d} | {ck} |" for p, d, ck in SURR) n_test = sum(m["splits"]["test"]["num_rows"] for m in man.values()) n_pert = sum(v["num_rows"] for m in man.values() for k, v in m["splits"].items() if k not in ("train", "validation", "test")) n_adv = sum(v["num_rows"] for m in man.values() for k, v in m["splits"].items() if k.split("_")[0] in ("clip", "metaclip", "siglip2")) body = f""" # RobustGenBench **A standardized benchmark for robust generalization of image classifiers across common and adversarial ($\\ell_1, \\ell_2, \\ell_\\infty$) perturbations.** [📄 Paper](https://openreview.net/forum?id=KDsuVST8by) · 💻 [Code](https://github.com/legolasflagstaff/robust_training) · 📜 [Citation](#citation) RobustGenBench evaluates how well a classifier keeps its accuracy on perturbation types it was not trained against. It provides six downstream classification datasets with fixed splits at 224×224 resolution, together with perturbed copies of every test set: - **Common corruptions** (11 types, severity 3): model-independent, the same images for every model. - **Random uniform noise** ($\\ell_\\infty \\le 30/255$): a control for the adversarial perturbations. - **Transfer adversarial perturbations** ({n_adv:,} images): crafted with AutoAttack on 5 open-weight vision-language surrogates, across 7 budgets in $\\ell_1$, $\\ell_2$, $\\ell_\\infty$. Because the adversarial images are pre-computed, any model, including API-only systems such as vision-enabled LLMs, can be evaluated **by inference alone**, without GPU access. For white-box evaluation, attack your own model on the clean `test` split. In total: {n_test:,} clean test images and {n_pert:,} perturbed test images. ## Quick start ```python from datasets import load_dataset repo = "legolasflagstaff/RobustGenBench" # Clean and model-independent splits: config "". clean = load_dataset(repo, "uc-merced-land-use-dataset", split="test") common = load_dataset(repo, "uc-merced-land-use-dataset", split="common") # Transfer attacks: config "-", one split per budget. adv = load_dataset(repo, "uc-merced-land-use-dataset-clip_vith14", split="linf_30") row = adv[0] row["image"] # PIL.Image, 224×224 RGB adv.features["label"].int2str(row["label"]) # class name row["image_id"] # aligns with the clean image of the same id ``` Evaluate a classifier on every perturbation setting of one dataset: ```python from datasets import load_dataset, get_dataset_config_names, get_dataset_split_names repo, name = "legolasflagstaff/RobustGenBench", "flowers-102" settings = [(name, s) for s in ("test", "common", "random_linf_30")] for cfg in get_dataset_config_names(repo): if cfg.startswith(name + "-"): # one config per surrogate settings += [(cfg, s) for s in get_dataset_split_names(repo, cfg)] for cfg, split in settings: ds = load_dataset(repo, cfg, split=split) acc = sum(predict(x["image"]) == x["label"] for x in ds) / len(ds) # your model here print(f"{{cfg:34s}} {{split:15s}} {{acc:.3f}}") ``` All perturbed splits are aligned with `test` by `image_id`: row *i* of every perturbed split is a perturbed version of row *i* of `test`, with the same label. ## Datasets | Config | Dataset | Domain | Granularity | Classes | Train | Validation | Test | |---|---|---|---|---|---|---|---| {ds_rows} Test sets are standardized to at most 1,000 images by uniform sampling, preserving all classes. All images are resized to 224×224×3 and stored as lossless PNG. ## Configs and splits | Config | Split | Content | |---|---|---| | `` | `train`, `validation` | Clean images, for fine-tuning. | | `` | `test` | Clean test images, the reference for all perturbed splits. | | `` | `common` | Each test image with one of 11 common corruptions at severity 3 (column `corruption`). | | `` | `random_linf_30` | Uniform random noise with $\\lVert\\delta\\rVert_\\infty \\le 30/255$. | | `-` | `_` | Transfer adversarial images, e.g. config `flowers-102-clip_vitb16`, split `linf_30`. | The Parquet files themselves live under `data//`. ### Common corruptions Shot noise, impulse noise, defocus blur, motion blur, zoom blur, snow, brightness, contrast, elastic transform, pixelate, JPEG compression, all at severity 3 of the ImageNet-C scale. The test set is split into 11 contiguous blocks of ⌊n/11⌋ images, one per corruption in the order above, and the remaining images wrap around to the first corruption (column `corruption`). The images are fixed, so every model is evaluated on identical (image, corruption) pairs. ### Adversarial perturbations Perturbations are crafted with the standard AutoAttack ensemble (APGD-CE, APGD-T, FAB-T, Square) against zero-shot surrogate classifiers. Each surrogate predicts the class whose text embedding (`"a photo of a {{class}}"`) is closest to the image embedding. AutoAttack only perturbs images the surrogate classifies correctly; other images are copied unchanged (`is_modified = false`). | Norm | Budgets $\\epsilon$ | Splits | |---|---|---| | $\\ell_1$ | 75, 300 | `l1_75`, `l1_300` | | $\\ell_2$ | 2, 8 | `l2_2`, `l2_8` | | $\\ell_\\infty$ | 4/255, 8/255, 30/255 | `linf_4`, `linf_8`, `linf_30` | Budgets are expressed on pixel values in $[0, 1]$; the `epsilon` column stores the exact value (e.g. 0.1176 for 30/255). | Config suffix | Model | Checkpoint | |---|---|---| {surr_rows} ### Coverage SigLIP-family surrogates classify the fine-grained datasets poorly, and a surrogate that misclassifies the clean image provides no attack signal. SigLIP2 SO400M is therefore provided on the three coarse-grained datasets only. SigLIP2 base is provided at $\\ell_\\infty$ 30/255 only; on the fine-grained datasets it leaves most images unmodified (see `is_modified`). {chr(10).join(cov)} ## Data fields | Field | Type | Description | |---|---|---| | `image` | image | 224×224 RGB PNG. | | `label` | class label | Ground-truth class (use `features["label"].names` for names). | | `image_id` | int32 | Index of the source image within its split; aligns perturbed splits with `test`. | | `perturbation` | string | `clean`, `common_corruption_severity3`, `random_uniform`, or `transfer_autoattack`. | | `surrogate` | string | Surrogate used to craft the attack (null otherwise). | | `norm` | string | `l1`, `l2`, or `linf` (null for clean and common). | | `epsilon` | float32 | Perturbation budget (null for clean and common). | | `corruption` | string | Common corruption applied (`common` split only). | | `is_modified` | bool | Whether the image differs from its clean counterpart. | ## Evaluation protocol RobustGenBench reports accuracy per (dataset, perturbation setting), aggregated with: - **Sum score**: sum of accuracies over all (dataset, setting) pairs. Pool-independent; use it to compare new models with published results. - **Borda score**: rank-based consistency across pairs, only meaningful within a fixed pool of models. The paper uses two sets of settings: - **Fine-tuned vision models (5 settings):** `test`, `common`, and white-box AutoAttack on the evaluated model at $\\ell_1 = 75$, $\\ell_2 = 2$, $\\ell_\\infty = 4/255$, crafted from the clean `test` split. Maximum sum score: 30. - **Black-box models, e.g. vision-enabled LLMs (9 settings):** `test`, `common`, and the 7 transfer budgets, taking the strongest surrogate per dataset and setting. ## Intended use and limitations **Intended use:** held-out evaluation of the robustness of image classifiers, fine-tuned or zero-shot, including API-only models. Do not train on the test or perturbed splits. **Limitations** - Transfer attacks give an upper bound on robust accuracy. They are not a substitute for white-box or adaptive attacks when model access is available. - All surrogates are attention-based, so transfer to convolutional targets is weaker. - Budgets are not matched across norms; compare norms only at the intensities provided. - Common corruptions are evaluated at a single severity. - Coverage is limited to six source taxonomies; results do not imply robustness on open-world imagery. **Biases.** The source datasets inherit the biases of their collection, for example Western car models (Stanford Cars) and breeds common in the UK (Oxford-IIIT Pet). Some images may incidentally show people or license plates; no additional anonymization was performed. ## License The perturbed images, splits, and metadata produced for RobustGenBench are released under **[CC BY-NC 4.0](https://creativecommons.org/licenses/by-nc/4.0/)**. This license does not override the terms of the source datasets: every image is a derivative of an upstream image whose rights remain with its owners. Users must comply with both licenses; where they differ, the more restrictive applies. | Source | Homepage | Upstream terms | |---|---|---| {lic_rows} ## Citation ```bibtex @inproceedings{{heuillet2026robustgenbench, title = {{RobustGenBench: A Benchmark for Robust Generalization to Adversarial and Common Perturbations, with Applications to Vision and Vision-Enabled Large Language Models}}, author = {{Heuillet, Maxime and Ngnaw{{\\'e}}, Jonas and Pequignot, Yann and Bhagwatkar, Rishika and Larouche, Alexandre and Gagn{{\\'e}}, Christian and Rish, Irina and Ahmad, Ola and Durand, Audrey}}, booktitle = {{The Fortieth Annual Conference on Neural Information Processing Systems Evaluations and Datasets Track}}, url = {{https://openreview.net/forum?id=KDsuVST8by}}, year = {{2026}} }} ``` Please also cite the six source datasets. ## Versions - **v2.1** (current): the `common` split contains the common-corruption images of the original processed archives. - **v2.0**: Parquet layout with Dataset Viewer support; restricted to the surrogates reported in the paper. - **v1.0**: original `.tar.zst` archives, kept for reproducibility under the git tag [`v1.0-archives`](https://huggingface.co/datasets/legolasflagstaff/RobustGenBench/tree/v1.0-archives). """ (ROOT / "README.md").write_text("\n".join(y) + "\n" + body) print("README.md written,", len(y), "YAML lines")