legolasflagstaff commited on
Commit
7a9682d
·
1 Parent(s): 34cf76c

v2.1: common split from the original processed archives (#2)

Browse files

- v2.1: common split from the original processed archives (391dcfa7978a26d52f098e975ea5bfded97d2f46)

README.md CHANGED
@@ -535,7 +535,7 @@ The Parquet files themselves live under `data/<dataset>/`.
535
 
536
  ### Common corruptions
537
 
538
- 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. Test image *i* receives corruption *i* mod 11; the assignment is deterministic, so every model is evaluated on identical (image, corruption) pairs.
539
 
540
  ### Adversarial perturbations
541
 
@@ -660,5 +660,6 @@ Please also cite the six source datasets.
660
 
661
  ## Versions
662
 
663
- - **v2.0** (current): Parquet layout with Dataset Viewer support; restricted to the surrogates reported in the paper.
 
664
  - **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).
 
535
 
536
  ### Common corruptions
537
 
538
+ 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.
539
 
540
  ### Adversarial perturbations
541
 
 
660
 
661
  ## Versions
662
 
663
+ - **v2.1** (current): the `common` split contains the common-corruption images of the original processed archives, used throughout the paper.
664
+ - **v2.0**: Parquet layout with Dataset Viewer support; restricted to the surrogates reported in the paper.
665
  - **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).
data/caltech101/common-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9973bf92c8c95333beb703962885e9c8c91e56d820a451e5b09cc79dba617302
3
- size 57539187
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:12bb5d88399bc7ad9a9c99771ba03602dd8faffd18f00f980b9d2986e4f66e68
3
+ size 67310473
data/fgvc-aircraft-2013b/common-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:ce48d91fb2b1cf10c7e07d8a81e8a8aa11f3bbf9f1579e9124e455379d1a4282
3
- size 53207412
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:13a1d4a3381c02dd4578123c35d5b63f8a84c7585205ae723b885bce3f5906a8
3
+ size 66692591
data/flowers-102/common-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c8d31d578aacd1dbd164e44ba12995f5c488e9d82b4bd25fb6fc9bfe5b668590
3
- size 67012088
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1b92f77be84eab0c527fe78b0d307761b2e7a73bb4d32c78a83f8de0d38a3e36
3
+ size 79720433
data/oxford-iiit-pet/common-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:15801aa959613a21712501d0ea44b1c523fb8721e60b7f5befa445d9f0f48471
3
- size 64473933
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5cfb31438d1c947dff9c6a721c22e0b16079d045d3e59d054c6e08f1badad402
3
+ size 78349129
data/stanford_cars/common-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:d5c85b822a255ec374a7179b468cdbe785e00ac05f9c125de8abc5fb9c35340f
3
- size 61014834
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5d51fa1477441c09b62b2d3586625c3bb91bb4a0520f82d10ceb6b0ba0d20bf0
3
+ size 73166263
data/uc-merced-land-use-dataset/common-00000-of-00001.parquet CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:f382e9d7cd42c01e6d9c60b70d412c5417f1b1e2c0796f6d2b03db959b82687e
3
- size 28614938
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e7c0ad4de5202b76c62d001825d8237c3980f9c0132ec573d9a9a4396a30078
3
+ size 33152732
scripts/build_parquet.py CHANGED
@@ -32,8 +32,10 @@ ROWS_PER_GROUP = 100 # small row groups keep the Dataset Viewer responsive
32
  DATASETS = ["caltech101", "fgvc-aircraft-2013b", "flowers-102",
33
  "oxford-iiit-pet", "stanford_cars", "uc-merced-land-use-dataset"]
34
 
35
- # Round-robin assignment used to build the released common-corruption images:
36
- # image i receives COMMON_CORRUPTIONS[i % 11] (verified on the pixel data).
 
 
37
  COMMON_CORRUPTIONS = ["shot_noise", "impulse_noise", "defocus_blur", "motion_blur",
38
  "zoom_blur", "snow", "brightness", "contrast",
39
  "elastic_transform", "pixelate", "jpeg_compression"]
@@ -61,6 +63,9 @@ THREATS = {
61
  KEEP_ONLY = {"siglip2_base": {"linf_eps30_autoattack_standard"}}
62
 
63
 
 
 
 
64
  def read_archive(path, split):
65
  with open(path, "rb") as f:
66
  buf = io.BytesIO(zstd.ZstdDecompressor().stream_reader(f).read())
@@ -101,7 +106,7 @@ def pixels(b):
101
  return np.asarray(PILImage.open(io.BytesIO(b)).convert("RGB"))
102
 
103
 
104
- def build(dataset):
105
  class_names_map = json.loads((SRC / "class_names" / f"{dataset}.json").read_text())
106
  class_names = [class_names_map[str(i)] for i in range(len(class_names_map))]
107
  feats = features(class_names)
@@ -119,8 +124,9 @@ def build(dataset):
119
  corruption=None, is_modified=False) for i, lab, b in items]
120
  summary[name] = write_split(recs, feats, out_dir, name)
121
 
122
- def perturbed(path, split_name, perturbation, surrogate, norm, eps, corr_fn=None):
123
- items = read_archive(path, "test")
 
124
  assert len(items) == len(clean_test), (path, len(items))
125
  recs = []
126
  for i, lab, b in items:
@@ -133,9 +139,10 @@ def build(dataset):
133
  summary[split_name] = write_split(recs, feats, out_dir, split_name)
134
 
135
  adv = SRC / "adversarial"
136
- perturbed(adv / f"common/common_severity3/{dataset}__common_severity3_processed.tar.zst",
137
- "common", "common_corruption_severity3", None, None, None,
138
- corr_fn=lambda i: COMMON_CORRUPTIONS[i % len(COMMON_CORRUPTIONS)])
 
139
  perturbed(adv / f"random/linf_eps30_random_uniform/{dataset}__random__linf_eps30_random_uniform_processed.tar.zst",
140
  "random_linf_30", "random_uniform", None, "linf", 30 / 255)
141
 
 
32
  DATASETS = ["caltech101", "fgvc-aircraft-2013b", "flowers-102",
33
  "oxford-iiit-pet", "stanford_cars", "uc-merced-land-use-dataset"]
34
 
35
+ # Common corruptions: the test_common/ split of the original processed archives
36
+ # (paper_code/save_final_dataset.py), i.e. the images used to evaluate the vision
37
+ # models. Image i receives COMMON_CORRUPTIONS[(i // s) % 11] with s = n // 11
38
+ # (paper_code/corruptions/common.py; verified on the pixel data).
39
  COMMON_CORRUPTIONS = ["shot_noise", "impulse_noise", "defocus_blur", "motion_blur",
40
  "zoom_blur", "snow", "brightness", "contrast",
41
  "elastic_transform", "pixelate", "jpeg_compression"]
 
63
  KEEP_ONLY = {"siglip2_base": {"linf_eps30_autoattack_standard"}}
64
 
65
 
66
+ ORIG = Path(__file__).parent / "orig" # archives at revision 0790625f (with test_common/)
67
+
68
+
69
  def read_archive(path, split):
70
  with open(path, "rb") as f:
71
  buf = io.BytesIO(zstd.ZstdDecompressor().stream_reader(f).read())
 
106
  return np.asarray(PILImage.open(io.BytesIO(b)).convert("RGB"))
107
 
108
 
109
+ def build(dataset, only=None):
110
  class_names_map = json.loads((SRC / "class_names" / f"{dataset}.json").read_text())
111
  class_names = [class_names_map[str(i)] for i in range(len(class_names_map))]
112
  feats = features(class_names)
 
124
  corruption=None, is_modified=False) for i, lab, b in items]
125
  summary[name] = write_split(recs, feats, out_dir, name)
126
 
127
+ def perturbed(path, split_name, perturbation, surrogate, norm, eps, corr_fn=None,
128
+ split="test"):
129
+ items = read_archive(path, split)
130
  assert len(items) == len(clean_test), (path, len(items))
131
  recs = []
132
  for i, lab, b in items:
 
139
  summary[split_name] = write_split(recs, feats, out_dir, split_name)
140
 
141
  adv = SRC / "adversarial"
142
+ step = max(1, len(clean_test) // len(COMMON_CORRUPTIONS))
143
+ perturbed(ORIG / f"{dataset}_processed.tar.zst", "common", "common_corruption_severity3",
144
+ None, None, None, split="test_common",
145
+ corr_fn=lambda i: COMMON_CORRUPTIONS[(i // step) % len(COMMON_CORRUPTIONS)])
146
  perturbed(adv / f"random/linf_eps30_random_uniform/{dataset}__random__linf_eps30_random_uniform_processed.tar.zst",
147
  "random_linf_30", "random_uniform", None, "linf", 30 / 255)
148
 
scripts/make_card.py CHANGED
@@ -156,7 +156,7 @@ The Parquet files themselves live under `data/<dataset>/`.
156
 
157
  ### Common corruptions
158
 
159
- 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. Test image *i* receives corruption *i* mod 11; the assignment is deterministic, so every model is evaluated on identical (image, corruption) pairs.
160
 
161
  ### Adversarial perturbations
162
 
@@ -242,7 +242,8 @@ Please also cite the six source datasets.
242
 
243
  ## Versions
244
 
245
- - **v2.0** (current): Parquet layout with Dataset Viewer support; restricted to the surrogates reported in the paper.
 
246
  - **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).
247
  """
248
  (ROOT / "README.md").write_text("\n".join(y) + "\n" + body)
 
156
 
157
  ### Common corruptions
158
 
159
+ 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.
160
 
161
  ### Adversarial perturbations
162
 
 
242
 
243
  ## Versions
244
 
245
+ - **v2.1** (current): the `common` split contains the common-corruption images of the original processed archives, used throughout the paper.
246
+ - **v2.0**: Parquet layout with Dataset Viewer support; restricted to the surrogates reported in the paper.
247
  - **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).
248
  """
249
  (ROOT / "README.md").write_text("\n".join(y) + "\n" + body)