Datasets:
Tasks:
Image Classification
Modalities:
Image
Formats:
imagefolder
Languages:
English
Size:
10K - 100K
License:
Add files using upload-large-folder tool
Browse files- .DS_Store +0 -0
- README.md +144 -0
- colored_mnist.py +99 -0
- images/blue_312.png +3 -0
- images/green_8218.png +3 -0
- images/red_8428.png +3 -0
- training/.DS_Store +0 -0
- training/9/blue_1950.png +3 -0
- training/9/blue_2041.png +3 -0
- training/9/blue_2860.png +3 -0
- training/9/blue_5276.png +3 -0
- training/9/blue_5538.png +3 -0
- training/9/blue_5539.png +3 -0
- training/9/blue_6145.png +3 -0
- training/9/blue_6964.png +3 -0
- training/9/blue_7676.png +3 -0
- training/9/blue_7886.png +3 -0
- training/9/blue_8035.png +3 -0
- training/9/blue_8356.png +3 -0
- training/9/blue_980.png +3 -0
- training/9/green_1169.png +3 -0
- training/9/green_1960.png +3 -0
- training/9/green_3030.png +3 -0
- training/9/green_3193.png +3 -0
- training/9/green_3583.png +3 -0
- training/9/green_3636.png +3 -0
- training/9/green_4206.png +3 -0
- training/9/green_4830.png +3 -0
- training/9/green_6149.png +3 -0
- training/9/green_631.png +3 -0
- training/9/green_6438.png +3 -0
- training/9/green_6439.png +3 -0
- training/9/green_7069.png +3 -0
- training/9/green_7108.png +3 -0
- training/9/green_7256.png +3 -0
- training/9/green_7727.png +3 -0
- training/9/green_7733.png +3 -0
- training/9/green_8005.png +3 -0
- training/9/red_110.png +3 -0
- training/9/red_1740.png +3 -0
- training/9/red_2116.png +3 -0
- training/9/red_3355.png +3 -0
- training/9/red_3382.png +3 -0
- training/9/red_4611.png +3 -0
- training/9/red_4771.png +3 -0
- training/9/red_501.png +3 -0
- training/9/red_529.png +3 -0
- training/9/red_5532.png +3 -0
- training/9/red_6205.png +3 -0
- training/9/red_7873.png +3 -0
.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
README.md
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Colored MNIST Dataset
|
| 2 |
+
|
| 3 |
+
A comprehensive dataset of MNIST digits with RGB colored backgrounds, designed for multi-objective classification tasks including digit recognition and background color classification.
|
| 4 |
+
|
| 5 |
+
  
|
| 6 |
+
|
| 7 |
+
## Overview
|
| 8 |
+
|
| 9 |
+
This dataset extends the classic MNIST digit dataset by adding colored backgrounds (blue, green, red) to create a multi-label classification challenge. Each image contains:
|
| 10 |
+
- **Digit label**: 0-9 (digit recognition)
|
| 11 |
+
- **Color label**: blue, green, red (background color classification)
|
| 12 |
+
- **Image format**: 28×28 RGB PNG files
|
| 13 |
+
|
| 14 |
+
## Dataset Statistics
|
| 15 |
+
|
| 16 |
+
### Training Set (8,835 samples)
|
| 17 |
+
| Digit | Count | Digit | Count |
|
| 18 |
+
|-------|-------|-------|-------|
|
| 19 |
+
| 0 | 868 | 5 | 764 |
|
| 20 |
+
| 1 | 1,000 | 6 | 893 |
|
| 21 |
+
| 2 | 858 | 7 | 948 |
|
| 22 |
+
| 3 | 909 | 8 | 835 |
|
| 23 |
+
| 4 | 883 | 9 | 877 |
|
| 24 |
+
|
| 25 |
+
### Test Set (10,000 samples)
|
| 26 |
+
| Digit | Count | Digit | Count |
|
| 27 |
+
|-------|-------|-------|-------|
|
| 28 |
+
| 0 | 980 | 5 | 892 |
|
| 29 |
+
| 1 | 1,135 | 6 | 958 |
|
| 30 |
+
| 2 | 1,032 | 7 | 1,028 |
|
| 31 |
+
| 3 | 1,010 | 8 | 974 |
|
| 32 |
+
| 4 | 982 | 9 | 1,009 |
|
| 33 |
+
|
| 34 |
+
### Color Distribution
|
| 35 |
+
- **Blue**: ~2,946 training samples
|
| 36 |
+
- **Green**: ~2,968 training samples
|
| 37 |
+
- **Red**: ~2,921 training samples
|
| 38 |
+
|
| 39 |
+
## Directory Structure
|
| 40 |
+
|
| 41 |
+
```
|
| 42 |
+
colored_mnist/
|
| 43 |
+
├── README.md
|
| 44 |
+
├── colored_mnist.py # HuggingFace dataset loader
|
| 45 |
+
├── images/ # Example images
|
| 46 |
+
│ ├── blue_312.png # Blue background, digit 3
|
| 47 |
+
│ ├── green_8218.png # Green background, digit 8
|
| 48 |
+
│ └── red_8428.png # Red background, digit 4
|
| 49 |
+
├── training/ # Training data
|
| 50 |
+
│ ├── 0/ # Digit 0 samples
|
| 51 |
+
│ │ ├── blue_1015.png
|
| 52 |
+
│ │ ├── green_1000.png
|
| 53 |
+
│ │ └── red_1028.png
|
| 54 |
+
│ └── ... # Digits 1-9
|
| 55 |
+
├── testing/ # Test data
|
| 56 |
+
│ ├── 0/ # Digit 0 samples
|
| 57 |
+
│ │ ├── blue_10.png
|
| 58 |
+
│ │ ├── green_1084.png
|
| 59 |
+
│ │ └── red_1001.png
|
| 60 |
+
│ └── ... # Digits 1-9
|
| 61 |
+
├── training.h5 # HDF5 format (optional)
|
| 62 |
+
└── testing.h5 # HDF5 format (optional)
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
## Usage
|
| 66 |
+
|
| 67 |
+
### Loading with HuggingFace Datasets
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
from datasets import load_dataset
|
| 71 |
+
|
| 72 |
+
# Load the dataset using the custom script
|
| 73 |
+
dataset = load_dataset("FrankCCCCC/colored_mnist", trust_remote_code=True)
|
| 74 |
+
|
| 75 |
+
print(f"Train samples: {len(dataset['train'])}")
|
| 76 |
+
print(f"Test samples: {len(dataset['test'])}")
|
| 77 |
+
|
| 78 |
+
# Access a sample
|
| 79 |
+
sample = dataset['train'][0]
|
| 80 |
+
print(f"Image shape: {sample['image'].shape}") # PIL.Image: Raw Image with shape (28, 28, 3)
|
| 81 |
+
print(f"Digit Label: {sample['digit_label']}") # Integer: Digit class 0-9
|
| 82 |
+
print(f"Color Label: {sample['color_label']}") # String: Color class: 'blue', 'green', 'red'
|
| 83 |
+
print(f"filename: {sample['filename']}") # String: file name
|
| 84 |
+
print(f"image_path: {sample['image_path']}") # String: file path
|
| 85 |
+
```
|
| 86 |
+
|
| 87 |
+
## Applications
|
| 88 |
+
|
| 89 |
+
This dataset is ideal for:
|
| 90 |
+
|
| 91 |
+
1. **Multi-task Learning**: Train models to simultaneously classify digits and colors
|
| 92 |
+
2. **Domain Adaptation**: Study how background colors affect digit recognition
|
| 93 |
+
3. **Bias Analysis**: Investigate color-digit correlations and model robustness
|
| 94 |
+
4. **Transfer Learning**: Pre-train on one task (digit/color) and fine-tune on another
|
| 95 |
+
5. **Curriculum Learning**: Start with single-task then progress to multi-task
|
| 96 |
+
6. **Attention Mechanisms**: Visualize what models focus on (digit vs. background)
|
| 97 |
+
|
| 98 |
+
## Features
|
| 99 |
+
|
| 100 |
+
- **Multi-label Classification**: Both digit and color labels for each image
|
| 101 |
+
- **Balanced Colors**: Approximately equal distribution across blue, green, red
|
| 102 |
+
- **Standard Format**: Compatible with PyTorch, TensorFlow, and HuggingFace
|
| 103 |
+
- **PIL Integration**: Images loaded as PIL objects for easy preprocessing
|
| 104 |
+
- **Metadata**: Includes original filename and image path information
|
| 105 |
+
|
| 106 |
+
## Dataset Format
|
| 107 |
+
|
| 108 |
+
Each sample contains:
|
| 109 |
+
```python
|
| 110 |
+
{
|
| 111 |
+
'image': PIL.Image, # 28×28 RGB image
|
| 112 |
+
'digit_label': int, # Digit class (0-9)
|
| 113 |
+
'color_label': str, # Color class ('blue'|'green'|'red')
|
| 114 |
+
'filename': str, # Original filename
|
| 115 |
+
'image_path': str # Full path to image file
|
| 116 |
+
}
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
## Requirements
|
| 120 |
+
|
| 121 |
+
```bash
|
| 122 |
+
pip install datasets pillow torch torchvision matplotlib numpy
|
| 123 |
+
```
|
| 124 |
+
|
| 125 |
+
## Citation
|
| 126 |
+
|
| 127 |
+
```bibtex
|
| 128 |
+
@misc{colorized-mnist,
|
| 129 |
+
title={Colorized MNIST},
|
| 130 |
+
author={Original MNIST Dataset},
|
| 131 |
+
year={2024},
|
| 132 |
+
url={https://github.com/jayaneetha/colorized-MNIST}
|
| 133 |
+
}
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
## License
|
| 137 |
+
|
| 138 |
+
This dataset follows the same license as the original MNIST dataset. Please cite both the original MNIST work and this colored extension when using this dataset.
|
| 139 |
+
|
| 140 |
+
## Acknowledgments
|
| 141 |
+
|
| 142 |
+
- Based on the original MNIST dataset by Yann LeCun et al.
|
| 143 |
+
- Color augmentation creates additional research opportunities for multi-task learning
|
| 144 |
+
- Compatible with modern deep learning frameworks and HuggingFace ecosystem
|
colored_mnist.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import datasets
|
| 3 |
+
from datasets import Features, ClassLabel, Image, Value
|
| 4 |
+
from PIL import Image as PILImage
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
_DESCRIPTION = """\
|
| 8 |
+
Colored MNIST is a dataset of MNIST digits with RGB colored backgrounds.
|
| 9 |
+
This dataset can be used for multi-objective classification tasks including:
|
| 10 |
+
- Digit recognition (0-9)
|
| 11 |
+
- Background color classification (blue, green, red)
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
_CITATION = """\
|
| 15 |
+
@misc{colorized-mnist,
|
| 16 |
+
title={Colorized MNIST},
|
| 17 |
+
url={https://github.com/jayaneetha/colorized-MNIST},
|
| 18 |
+
}
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
_HOMEPAGE = "https://github.com/jayaneetha/colorized-MNIST"
|
| 22 |
+
|
| 23 |
+
_LICENSE = ""
|
| 24 |
+
|
| 25 |
+
class ColoredMnist(datasets.GeneratorBasedBuilder):
|
| 26 |
+
"""Colored MNIST dataset with multi-label classification."""
|
| 27 |
+
|
| 28 |
+
VERSION = datasets.Version("1.0.0")
|
| 29 |
+
|
| 30 |
+
def _info(self):
|
| 31 |
+
features = Features({
|
| 32 |
+
'image': Image(),
|
| 33 |
+
'digit_label': ClassLabel(num_classes=10, names=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
|
| 34 |
+
'color_label': ClassLabel(num_classes=3, names=['blue', 'green', 'red']),
|
| 35 |
+
'image_path': Value('string'),
|
| 36 |
+
'filename': Value('string')
|
| 37 |
+
})
|
| 38 |
+
|
| 39 |
+
return datasets.DatasetInfo(
|
| 40 |
+
description=_DESCRIPTION,
|
| 41 |
+
features=features,
|
| 42 |
+
homepage=_HOMEPAGE,
|
| 43 |
+
license=_LICENSE,
|
| 44 |
+
citation=_CITATION,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
def _split_generators(self, dl_manager):
|
| 48 |
+
"""Returns SplitGenerators."""
|
| 49 |
+
# The dataset path should be provided as a data_dir, or use current directory
|
| 50 |
+
data_dir = self.config.data_dir if self.config.data_dir else os.path.dirname(os.path.abspath(__file__))
|
| 51 |
+
print(f"data_dir: {data_dir}")
|
| 52 |
+
|
| 53 |
+
return [
|
| 54 |
+
datasets.SplitGenerator(
|
| 55 |
+
name=datasets.Split.TRAIN,
|
| 56 |
+
gen_kwargs={
|
| 57 |
+
"data_dir": os.path.join(data_dir, "training"),
|
| 58 |
+
"split": "train",
|
| 59 |
+
},
|
| 60 |
+
),
|
| 61 |
+
datasets.SplitGenerator(
|
| 62 |
+
name=datasets.Split.TEST,
|
| 63 |
+
gen_kwargs={
|
| 64 |
+
"data_dir": os.path.join(data_dir, "testing"),
|
| 65 |
+
"split": "test",
|
| 66 |
+
},
|
| 67 |
+
),
|
| 68 |
+
]
|
| 69 |
+
|
| 70 |
+
def _generate_examples(self, data_dir, split):
|
| 71 |
+
"""Yields examples."""
|
| 72 |
+
idx = 0
|
| 73 |
+
raise NotImplementedError
|
| 74 |
+
|
| 75 |
+
for digit in range(10):
|
| 76 |
+
digit_dir = os.path.join(data_dir, str(digit))
|
| 77 |
+
if not os.path.exists(digit_dir):
|
| 78 |
+
continue
|
| 79 |
+
|
| 80 |
+
for filename in sorted(os.listdir(digit_dir)):
|
| 81 |
+
if filename.endswith('.png'):
|
| 82 |
+
# Extract color from filename (e.g., "blue_1015.png" -> "blue")
|
| 83 |
+
color = filename.split('_')[0]
|
| 84 |
+
if color not in ['blue', 'green', 'red']:
|
| 85 |
+
continue
|
| 86 |
+
|
| 87 |
+
image_path = os.path.join(digit_dir, filename)
|
| 88 |
+
|
| 89 |
+
# Load image as PIL Image
|
| 90 |
+
pil_image = PILImage.open(image_path)
|
| 91 |
+
|
| 92 |
+
yield idx, {
|
| 93 |
+
'image': pil_image,
|
| 94 |
+
'digit_label': digit,
|
| 95 |
+
'color_label': color,
|
| 96 |
+
'image_path': image_path,
|
| 97 |
+
'filename': filename,
|
| 98 |
+
}
|
| 99 |
+
idx += 1
|
images/blue_312.png
ADDED
|
Git LFS Details
|
images/green_8218.png
ADDED
|
Git LFS Details
|
images/red_8428.png
ADDED
|
Git LFS Details
|
training/.DS_Store
ADDED
|
Binary file (8.2 kB). View file
|
|
|
training/9/blue_1950.png
ADDED
|
Git LFS Details
|
training/9/blue_2041.png
ADDED
|
Git LFS Details
|
training/9/blue_2860.png
ADDED
|
Git LFS Details
|
training/9/blue_5276.png
ADDED
|
Git LFS Details
|
training/9/blue_5538.png
ADDED
|
Git LFS Details
|
training/9/blue_5539.png
ADDED
|
Git LFS Details
|
training/9/blue_6145.png
ADDED
|
Git LFS Details
|
training/9/blue_6964.png
ADDED
|
Git LFS Details
|
training/9/blue_7676.png
ADDED
|
Git LFS Details
|
training/9/blue_7886.png
ADDED
|
Git LFS Details
|
training/9/blue_8035.png
ADDED
|
Git LFS Details
|
training/9/blue_8356.png
ADDED
|
Git LFS Details
|
training/9/blue_980.png
ADDED
|
Git LFS Details
|
training/9/green_1169.png
ADDED
|
Git LFS Details
|
training/9/green_1960.png
ADDED
|
Git LFS Details
|
training/9/green_3030.png
ADDED
|
Git LFS Details
|
training/9/green_3193.png
ADDED
|
Git LFS Details
|
training/9/green_3583.png
ADDED
|
Git LFS Details
|
training/9/green_3636.png
ADDED
|
Git LFS Details
|
training/9/green_4206.png
ADDED
|
Git LFS Details
|
training/9/green_4830.png
ADDED
|
Git LFS Details
|
training/9/green_6149.png
ADDED
|
Git LFS Details
|
training/9/green_631.png
ADDED
|
Git LFS Details
|
training/9/green_6438.png
ADDED
|
Git LFS Details
|
training/9/green_6439.png
ADDED
|
Git LFS Details
|
training/9/green_7069.png
ADDED
|
Git LFS Details
|
training/9/green_7108.png
ADDED
|
Git LFS Details
|
training/9/green_7256.png
ADDED
|
Git LFS Details
|
training/9/green_7727.png
ADDED
|
Git LFS Details
|
training/9/green_7733.png
ADDED
|
Git LFS Details
|
training/9/green_8005.png
ADDED
|
Git LFS Details
|
training/9/red_110.png
ADDED
|
Git LFS Details
|
training/9/red_1740.png
ADDED
|
Git LFS Details
|
training/9/red_2116.png
ADDED
|
Git LFS Details
|
training/9/red_3355.png
ADDED
|
Git LFS Details
|
training/9/red_3382.png
ADDED
|
Git LFS Details
|
training/9/red_4611.png
ADDED
|
Git LFS Details
|
training/9/red_4771.png
ADDED
|
Git LFS Details
|
training/9/red_501.png
ADDED
|
Git LFS Details
|
training/9/red_529.png
ADDED
|
Git LFS Details
|
training/9/red_5532.png
ADDED
|
Git LFS Details
|
training/9/red_6205.png
ADDED
|
Git LFS Details
|
training/9/red_7873.png
ADDED
|
Git LFS Details
|