Upload 3 files
Browse files- README.md +98 -0
- animation0.gif +3 -0
- dsprites-noisy.py +99 -0
README.md
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: apache-2.0
|
3 |
+
---
|
4 |
+
# Dataset Card for Noisy dSprites
|
5 |
+
|
6 |
+
## Dataset Description
|
7 |
+
|
8 |
+
The **Noisy dSprites dataset** is a **synthetic 2D shapes dataset** designed for benchmarking algorithms in **disentangled representation learning** and **unsupervised representation learning**.
|
9 |
+
|
10 |
+
It is a variant of the original **dSprites dataset** introduced in the β-VAE paper. In this version, **random noise is added to the background** of each image, while the object shape itself remains unchanged. This allows researchers to evaluate **robustness to background noise** and test how well models can disentangle factors under noisy observation conditions.
|
11 |
+
|
12 |
+
The dataset consists of procedurally generated images of 2D sprites, under controlled variations of **6 known factors of variation**:
|
13 |
+
|
14 |
+
- Object color (1 value in original dSprites, fixed: white)
|
15 |
+
- Object shape (3 values: square, ellipse, heart)
|
16 |
+
- Object scale (6 values)
|
17 |
+
- Object orientation (40 values)
|
18 |
+
- Object position X (32 values)
|
19 |
+
- Object position Y (32 values)
|
20 |
+
|
21 |
+
All possible combinations of these factors are present exactly once, generating a total of **737,280 images** at a resolution of **64×64 pixels**. Each image is provided along with **Discrete latent classes** (indices for each factor) and **Continuous latent values**.
|
22 |
+
|
23 |
+
These variants allow systematic testing under **different nuisance variations** (color, noise, background texture, abstract factors).
|
24 |
+
|
25 |
+

|
26 |
+
|
27 |
+
The dataset is commonly used for **benchmarking disentanglement learning**, and can be used in conjunction with other variants:
|
28 |
+
|
29 |
+
- [randall-lab/dsprites (default, grayscale)](https://huggingface.co/datasets/randall-lab/dsprites)
|
30 |
+
- [randall-lab/dsprites-color](https://huggingface.co/datasets/randall-lab/dsprites-color)
|
31 |
+
- [randall-lab/dsprites-scream](https://huggingface.co/datasets/randall-lab/dsprites-scream)
|
32 |
+
|
33 |
+
## Dataset Source
|
34 |
+
- **Homepage**: [https://github.com/google-research/disentanglement_lib/](https://github.com/google-research/disentanglement_lib/tree/master)
|
35 |
+
- **License**: Apache License 2.0
|
36 |
+
- **Paper**: Francesco Locatello et al. _Challenging Common Assumptions in the Unsupervised Learning of Disentangled Representations_. ICML 2019.
|
37 |
+
|
38 |
+
## Dataset Structure
|
39 |
+
|Factors|Possible Classes (Indices)|Values|
|
40 |
+
|---|---|---|
|
41 |
+
|color|white=0 (fixed)|1.0 (fixed)|
|
42 |
+
|shape|square=0, ellipse=1, heart=2|1.0, 2.0, 3.0 (categorical)|
|
43 |
+
|scale|0,...,5|[0.5, 1.0] linearly spaced (6 values)|
|
44 |
+
|orientation|0,...,39|[0, 2π] radians (40 values)|
|
45 |
+
|posX|0,...,31|[0, 1] normalized position (32 values)|
|
46 |
+
|posY|0,...,31|[0, 1] normalized position (32 values)|
|
47 |
+
|
48 |
+
**Note:** In this Noisy variant, the object is kept white and the **background pixels are replaced with random noise**. Each image corresponds to a unique combination of these 6 factors. The images are stored in a **row-major order** (fastest-changing factor is `posY`, slowest-changing factor is `color`).
|
49 |
+
|
50 |
+
### Why no train/test split?
|
51 |
+
The Noisy dSprites dataset does not provide an official train/test split. It is designed for **representation learning research**, where the goal is to learn disentangled and interpretable latent factors. Since the dataset is a complete Cartesian product of all factor combinations, models typically require access to the full dataset to explore factor-wise variations.
|
52 |
+
|
53 |
+
## Example Usage
|
54 |
+
Below is a quick example of how to load this dataset via the Hugging Face Datasets library:
|
55 |
+
```python
|
56 |
+
from datasets import load_dataset
|
57 |
+
# Load the dataset
|
58 |
+
dataset = load_dataset("randall-lab/dsprites-noisy", split="train", trust_remote_code=True)
|
59 |
+
# Access a sample from the dataset
|
60 |
+
example = dataset[0]
|
61 |
+
image = example["image"]
|
62 |
+
label = example["label"] # [color_idx, shape_idx, scale_idx, orientation_idx, posX_idx, posY_idx]
|
63 |
+
label_values = example["label_values"] # corresponding continuous values
|
64 |
+
|
65 |
+
# Label Classes
|
66 |
+
color = example["color"] # 0
|
67 |
+
shape = example["shape"] # 0-2
|
68 |
+
scale = example["scale"] # 0-5
|
69 |
+
orientation = example["orientation"] # 0-39
|
70 |
+
posX = example["posX"] # 0-31
|
71 |
+
posY = example["posY"] # 0-31
|
72 |
+
# Label Values
|
73 |
+
color_value = example["colorValue"] # 1
|
74 |
+
shape_value = example["shapeValue"] # 1.0, 2.0, 3.0
|
75 |
+
scale_value = example["scaleValue"] # [0.5, 1]
|
76 |
+
orientation_value = example["orientationValue"] # [0, 2π]
|
77 |
+
posX_value = example["posXValue"] # [0, 1]
|
78 |
+
posY_value = example["posYValue"] # [0, 1]
|
79 |
+
|
80 |
+
image.show() # Display the image
|
81 |
+
print(f"Label (factors): {label}")
|
82 |
+
print(f"Label values (factors): {label_values}")
|
83 |
+
```
|
84 |
+
If you are using colab, you should update datasets to avoid errors
|
85 |
+
```
|
86 |
+
pip install -U datasets
|
87 |
+
```
|
88 |
+
## Citation
|
89 |
+
```
|
90 |
+
@inproceedings{locatello2019challenging,
|
91 |
+
title={Challenging Common Assumptions in the Unsupervised Learning of Disentangled Representations},
|
92 |
+
author={Locatello, Francesco and Bauer, Stefan and Lucic, Mario and Raetsch, Gunnar and Gelly, Sylvain and Sch{\"o}lkopf, Bernhard and Bachem, Olivier},
|
93 |
+
booktitle={International Conference on Machine Learning},
|
94 |
+
pages={4114--4124},
|
95 |
+
year={2019}
|
96 |
+
}
|
97 |
+
```
|
98 |
+
|
animation0.gif
ADDED
![]() |
Git LFS Details
|
dsprites-noisy.py
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import datasets
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
_DSPRITES_URL = "https://github.com/google-deepmind/dsprites-dataset/raw/refs/heads/master/dsprites_ndarray_co1sh3sc6or40x32y32_64x64.npz"
|
6 |
+
|
7 |
+
class DSprites(datasets.GeneratorBasedBuilder):
|
8 |
+
"""dSprites dataset: 3x6x40x32x32 factor combinations, 64x64 binary images."""
|
9 |
+
|
10 |
+
VERSION = datasets.Version("1.0.0")
|
11 |
+
|
12 |
+
def _info(self):
|
13 |
+
return datasets.DatasetInfo(
|
14 |
+
description=(
|
15 |
+
"Color dSprites dataset: procedurally generated 2D shapes dataset with known ground-truth factors, "
|
16 |
+
"commonly used for disentangled representation learning. "
|
17 |
+
"This is the ColorDSprites variant, where each object is randomly colored per sample, "
|
18 |
+
"while background remains black. "
|
19 |
+
"Factors: color (1), shape (3), scale (6), orientation (40), position X (32), position Y (32). "
|
20 |
+
"Images are 64x64 RGB."
|
21 |
+
),
|
22 |
+
features=datasets.Features(
|
23 |
+
{
|
24 |
+
"image": datasets.Image(), # (64, 64), grayscale
|
25 |
+
"index": datasets.Value("int32"), # index of the image
|
26 |
+
"label": datasets.Sequence(datasets.Value("int32")), # 6 factor indices (classes)
|
27 |
+
"label_values": datasets.Sequence(datasets.Value("float32")), # 6 factor continuous values
|
28 |
+
"color": datasets.Value("int32"), # color index (always 0)
|
29 |
+
"shape": datasets.Value("int32"), # shape index (0-2)
|
30 |
+
"scale": datasets.Value("int32"), # scale index (0-5)
|
31 |
+
"orientation": datasets.Value("int32"), # orientation index (0-39)
|
32 |
+
"posX": datasets.Value("int32"), # posX index (0-31)
|
33 |
+
"posY": datasets.Value("int32"), # posY index (0-31)
|
34 |
+
"colorValue": datasets.Value("float64"), # color index (always 0)
|
35 |
+
"shapeValue": datasets.Value("float64"), # shape index (0-2)
|
36 |
+
"scaleValue": datasets.Value("float64"), # scale index (0-5)
|
37 |
+
"orientationValue": datasets.Value("float64"), # orientation index (0-39)
|
38 |
+
"posXValue": datasets.Value("float64"), # posX index (0-31)
|
39 |
+
"posYValue": datasets.Value("float64"), # posY index (0-31)
|
40 |
+
}
|
41 |
+
),
|
42 |
+
supervised_keys=("image", "label"),
|
43 |
+
homepage="https://github.com/google-research/disentanglement_lib/tree/master",
|
44 |
+
license="apache-2.0",
|
45 |
+
citation="""@inproceedings{locatello2019challenging,
|
46 |
+
title={Challenging Common Assumptions in the Unsupervised Learning of Disentangled Representations},
|
47 |
+
author={Locatello, Francesco and Bauer, Stefan and Lucic, Mario and Raetsch, Gunnar and Gelly, Sylvain and Sch{\"o}lkopf, Bernhard and Bachem, Olivier},
|
48 |
+
booktitle={International Conference on Machine Learning},
|
49 |
+
pages={4114--4124},
|
50 |
+
year={2019}
|
51 |
+
}""",
|
52 |
+
)
|
53 |
+
|
54 |
+
def _split_generators(self, dl_manager):
|
55 |
+
npz_path = dl_manager.download(_DSPRITES_URL)
|
56 |
+
|
57 |
+
return [
|
58 |
+
datasets.SplitGenerator(
|
59 |
+
name=datasets.Split.TRAIN,
|
60 |
+
gen_kwargs={"npz_path": npz_path},
|
61 |
+
),
|
62 |
+
]
|
63 |
+
|
64 |
+
def _generate_examples(self, npz_path):
|
65 |
+
# Load npz
|
66 |
+
data = np.load(npz_path, allow_pickle=True)
|
67 |
+
images = data["imgs"] # shape: (737280, 64, 64), uint8
|
68 |
+
latents_classes = data["latents_classes"] # shape: (737280, 6), int64
|
69 |
+
latents_values = data["latents_values"] # shape: (737280, 6), float64
|
70 |
+
|
71 |
+
# Iterate over images
|
72 |
+
for idx in range(len(images)):
|
73 |
+
img = images[idx] # (64, 64), uint8
|
74 |
+
img = img.astype(np.float32) / 1.0
|
75 |
+
noise = np.random.uniform(0, 1, size=(64, 64, 3))
|
76 |
+
img_rgb = np.minimum(img[..., None] + noise, 1.0) * 255
|
77 |
+
img_pil = Image.fromarray(img_rgb.astype(np.uint8), mode="RGB")
|
78 |
+
|
79 |
+
factors_classes = latents_classes[idx].tolist() # [color_idx, shape_idx, scale_idx, orientation_idx, posX_idx, posY_idx]
|
80 |
+
factors_values = latents_values[idx].tolist()
|
81 |
+
|
82 |
+
yield idx, {
|
83 |
+
"image": img_pil,
|
84 |
+
"index": idx,
|
85 |
+
"label": factors_classes,
|
86 |
+
"label_values": factors_values,
|
87 |
+
"color": factors_classes[0], # always 0
|
88 |
+
"shape": factors_classes[1],
|
89 |
+
"scale": factors_classes[2],
|
90 |
+
"orientation": factors_classes[3],
|
91 |
+
"posX": factors_classes[4],
|
92 |
+
"posY": factors_classes[5],
|
93 |
+
"colorValue": factors_values[0], # always 0.0
|
94 |
+
"shapeValue": factors_values[1],
|
95 |
+
"scaleValue": factors_values[2],
|
96 |
+
"orientationValue": factors_values[3],
|
97 |
+
"posXValue": factors_values[4],
|
98 |
+
"posYValue": factors_values[5],
|
99 |
+
}
|