Datasets:
Tasks:
Image Classification
Modalities:
Image
Formats:
parquet
Sub-tasks:
multi-class-image-classification
Languages:
English
Size:
10K - 100K
ArXiv:
License:
Commit
•
c768752
0
Parent(s):
Update files from the datasets library (from 1.5.0)
Browse filesRelease notes: https://github.com/huggingface/datasets/releases/tag/1.5.0
- .gitattributes +27 -0
- README.md +191 -0
- dataset_infos.json +1 -0
- dummy/fashion_mnist/1.0.0/dummy_data.zip +3 -0
- fashion_mnist.py +143 -0
.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
annotations_creators:
|
3 |
+
- expert-generated
|
4 |
+
language_creators: []
|
5 |
+
languages: []
|
6 |
+
licenses:
|
7 |
+
- mit
|
8 |
+
multilinguality: []
|
9 |
+
size_categories:
|
10 |
+
- 10K<n<100K
|
11 |
+
source_datasets:
|
12 |
+
- original
|
13 |
+
task_categories:
|
14 |
+
- other
|
15 |
+
task_ids:
|
16 |
+
- other-other-image-classification
|
17 |
+
---
|
18 |
+
|
19 |
+
# Dataset Card for FashionMNIST
|
20 |
+
|
21 |
+
## Table of Contents
|
22 |
+
|
23 |
+
- [Dataset Description](#dataset-description)
|
24 |
+
- [Dataset Summary](#dataset-summary)
|
25 |
+
- [Supported Tasks](#supported-tasks-and-leaderboards)
|
26 |
+
- [Languages](#languages)
|
27 |
+
- [Dataset Structure](#dataset-structure)
|
28 |
+
- [Data Instances](#data-instances)
|
29 |
+
- [Data Fields](#data-instances)
|
30 |
+
- [Data Splits](#data-instances)
|
31 |
+
- [Dataset Creation](#dataset-creation)
|
32 |
+
- [Curation Rationale](#curation-rationale)
|
33 |
+
- [Source Data](#source-data)
|
34 |
+
- [Annotations](#annotations)
|
35 |
+
- [Personal and Sensitive Information](#personal-and-sensitive-information)
|
36 |
+
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
37 |
+
- [Social Impact of Dataset](#social-impact-of-dataset)
|
38 |
+
- [Discussion of Biases](#discussion-of-biases)
|
39 |
+
- [Other Known Limitations](#other-known-limitations)
|
40 |
+
- [Additional Information](#additional-information)
|
41 |
+
- [Dataset Curators](#dataset-curators)
|
42 |
+
- [Licensing Information](#licensing-information)
|
43 |
+
- [Citation Information](#citation-information)
|
44 |
+
- [Contributions](#contributions)
|
45 |
+
|
46 |
+
## Dataset Description
|
47 |
+
|
48 |
+
- **Homepage:** [GitHub](https://github.com/zalandoresearch/fashion-mnist)
|
49 |
+
- **Repository:** [GitHub](https://github.com/zalandoresearch/fashion-mnist)
|
50 |
+
- **Paper:** [arXiv](https://arxiv.org/pdf/1708.07747.pdf)
|
51 |
+
- **Leaderboard:**
|
52 |
+
- **Point of Contact:**
|
53 |
+
|
54 |
+
### Dataset Summary
|
55 |
+
|
56 |
+
Fashion-MNIST is a dataset of Zalando's article images—consisting of a training set of 60,000 examples and a test set of 10,000 examples. Each example is a 28x28 grayscale image, associated with a label from 10 classes. We intend Fashion-MNIST to serve as a direct drop-in replacement for the original MNIST dataset for benchmarking machine learning algorithms. It shares the same image size and structure of training and testing splits.
|
57 |
+
|
58 |
+
### Supported Tasks and Leaderboards
|
59 |
+
|
60 |
+
[More Information Needed]
|
61 |
+
|
62 |
+
### Languages
|
63 |
+
|
64 |
+
[More Information Needed]
|
65 |
+
|
66 |
+
## Dataset Structure
|
67 |
+
|
68 |
+
### Data Instances
|
69 |
+
|
70 |
+
A data point comprises an image and its label.
|
71 |
+
|
72 |
+
### Data Fields
|
73 |
+
|
74 |
+
- `image`: a 2d array of integers representing the 28x28 image.
|
75 |
+
- `label`: an integer between 0 and 9 representing the classes with the following mapping:
|
76 |
+
| Label | Description |
|
77 |
+
| --- | --- |
|
78 |
+
| 0 | T-shirt/top |
|
79 |
+
| 1 | Trouser |
|
80 |
+
| 2 | Pullover |
|
81 |
+
| 3 | Dress |
|
82 |
+
| 4 | Coat |
|
83 |
+
| 5 | Sandal |
|
84 |
+
| 6 | Shirt |
|
85 |
+
| 7 | Sneaker |
|
86 |
+
| 8 | Bag |
|
87 |
+
| 9 | Ankle boot |
|
88 |
+
|
89 |
+
### Data Splits
|
90 |
+
|
91 |
+
The data is split into training and test set. The training set contains 60,000 images and the test set 10,000 images.
|
92 |
+
|
93 |
+
## Dataset Creation
|
94 |
+
|
95 |
+
### Curation Rationale
|
96 |
+
|
97 |
+
**From the arXiv paper:**
|
98 |
+
The original MNIST dataset contains a lot of handwritten digits. Members of the AI/ML/Data Science community love this dataset and use it as a benchmark to validate their algorithms. In fact, MNIST is often the first dataset researchers try. "If it doesn't work on MNIST, it won't work at all", they said. "Well, if it does work on MNIST, it may still fail on others."
|
99 |
+
|
100 |
+
Here are some good reasons:
|
101 |
+
|
102 |
+
- MNIST is too easy. Convolutional nets can achieve 99.7% on MNIST. Classic machine learning algorithms can also achieve 97% easily. Check out our side-by-side benchmark for Fashion-MNIST vs. MNIST, and read "Most pairs of MNIST digits can be distinguished pretty well by just one pixel."
|
103 |
+
- MNIST is overused. In this April 2017 Twitter thread, Google Brain research scientist and deep learning expert Ian Goodfellow calls for people to move away from MNIST.
|
104 |
+
- MNIST can not represent modern CV tasks, as noted in this April 2017 Twitter thread, deep learning expert/Keras author François Chollet.
|
105 |
+
|
106 |
+
### Source Data
|
107 |
+
|
108 |
+
#### Initial Data Collection and Normalization
|
109 |
+
|
110 |
+
**From the arXiv paper:**
|
111 |
+
Fashion-MNIST is based on the assortment on Zalando’s website. Every fashion product on Zalando has a set of pictures shot by professional photographers, demonstrating different aspects of the product, i.e. front and back looks, details, looks with model and in an outfit. The original picture has a light-gray background (hexadecimal color: #fdfdfd) and stored in 762 × 1000 JPEG format. For efficiently serving different frontend components, the original picture is resampled with multiple resolutions, e.g. large, medium, small, thumbnail and tiny.
|
112 |
+
|
113 |
+
We use the front look thumbnail images of 70,000 unique products to build Fashion-MNIST. Those products come from different gender groups: men, women, kids and neutral. In particular, whitecolor products are not included in the dataset as they have low contrast to the background. The thumbnails (51 × 73) are then fed into the following conversion pipeline:
|
114 |
+
|
115 |
+
1. Converting the input to a PNG image.
|
116 |
+
2. Trimming any edges that are close to the color of the corner pixels. The ��closeness” is defined by the distance within 5% of the maximum possible intensity in RGB space.
|
117 |
+
3. Resizing the longest edge of the image to 28 by subsampling the pixels, i.e. some rows and columns are skipped over.
|
118 |
+
4. Sharpening pixels using a Gaussian operator of the radius and standard deviation of 1.0, with increasing effect near outlines.
|
119 |
+
5. Extending the shortest edge to 28 and put the image to the center of the canvas.
|
120 |
+
6. Negating the intensities of the image.
|
121 |
+
7. Converting the image to 8-bit grayscale pixels.
|
122 |
+
|
123 |
+
#### Who are the source image producers?
|
124 |
+
|
125 |
+
**From the arXiv paper:**
|
126 |
+
Every fashion product on Zalando has a set of pictures shot by professional photographers, demonstrating different aspects of the product, i.e. front and back looks, details, looks with model and in an outfit.
|
127 |
+
|
128 |
+
### Annotations
|
129 |
+
|
130 |
+
#### Annotation process
|
131 |
+
|
132 |
+
**From the arXiv paper:**
|
133 |
+
For the class labels, they use the silhouette code of the product. The silhouette code is manually labeled by the in-house fashion experts and reviewed by a separate team at Zalando. Each product Zalando is the Europe’s largest online fashion platform. Each product contains only one silhouette code.
|
134 |
+
|
135 |
+
#### Who are the annotators?
|
136 |
+
|
137 |
+
**From the arXiv paper:**
|
138 |
+
The silhouette code is manually labeled by the in-house fashion experts and reviewed by a separate team at Zalando.
|
139 |
+
|
140 |
+
### Personal and Sensitive Information
|
141 |
+
|
142 |
+
[More Information Needed]
|
143 |
+
|
144 |
+
## Considerations for Using the Data
|
145 |
+
|
146 |
+
### Social Impact of Dataset
|
147 |
+
|
148 |
+
[More Information Needed]
|
149 |
+
|
150 |
+
### Discussion of Biases
|
151 |
+
|
152 |
+
[More Information Needed]
|
153 |
+
|
154 |
+
### Other Known Limitations
|
155 |
+
|
156 |
+
[More Information Needed]
|
157 |
+
|
158 |
+
## Additional Information
|
159 |
+
|
160 |
+
### Dataset Curators
|
161 |
+
|
162 |
+
Han Xiao and Kashif Rasul and Roland Vollgraf
|
163 |
+
|
164 |
+
### Licensing Information
|
165 |
+
|
166 |
+
MIT Licence
|
167 |
+
|
168 |
+
### Citation Information
|
169 |
+
|
170 |
+
```
|
171 |
+
@article{DBLP:journals/corr/abs-1708-07747,
|
172 |
+
author = {Han Xiao and
|
173 |
+
Kashif Rasul and
|
174 |
+
Roland Vollgraf},
|
175 |
+
title = {Fashion-MNIST: a Novel Image Dataset for Benchmarking Machine Learning
|
176 |
+
Algorithms},
|
177 |
+
journal = {CoRR},
|
178 |
+
volume = {abs/1708.07747},
|
179 |
+
year = {2017},
|
180 |
+
url = {http://arxiv.org/abs/1708.07747},
|
181 |
+
archivePrefix = {arXiv},
|
182 |
+
eprint = {1708.07747},
|
183 |
+
timestamp = {Mon, 13 Aug 2018 16:47:27 +0200},
|
184 |
+
biburl = {https://dblp.org/rec/bib/journals/corr/abs-1708-07747},
|
185 |
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
186 |
+
}
|
187 |
+
```
|
188 |
+
|
189 |
+
### Contributions
|
190 |
+
|
191 |
+
Thanks to [@gchhablani](https://github.com/gchablani) for adding this dataset.
|
dataset_infos.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"fashion_mnist": {"description": "Fashion-MNIST is a dataset of Zalando's article images\u2014consisting of a training set of \n60,000 examples and a test set of 10,000 examples. Each example is a 28x28 grayscale image, \nassociated with a label from 10 classes. We intend Fashion-MNIST to serve as a direct drop-in \nreplacement for the original MNIST dataset for benchmarking machine learning algorithms. \nIt shares the same image size and structure of training and testing splits.\n", "citation": "@article{DBLP:journals/corr/abs-1708-07747,\n author = {Han Xiao and\n Kashif Rasul and\n Roland Vollgraf},\n title = {Fashion-MNIST: a Novel Image Dataset for Benchmarking Machine Learning\n Algorithms},\n journal = {CoRR},\n volume = {abs/1708.07747},\n year = {2017},\n url = {http://arxiv.org/abs/1708.07747},\n archivePrefix = {arXiv},\n eprint = {1708.07747},\n timestamp = {Mon, 13 Aug 2018 16:47:27 +0200},\n biburl = {https://dblp.org/rec/bib/journals/corr/abs-1708-07747},\n bibsource = {dblp computer science bibliography, https://dblp.org}\n}\n", "homepage": "https://github.com/zalandoresearch/fashion-mnist", "license": "", "features": {"image": {"shape": [28, 28], "dtype": "uint8", "id": null, "_type": "Array2D"}, "label": {"num_classes": 10, "names": ["T - shirt / top", "Trouser", "Pullover", "Dress", "Coat", "Sandal", "Shirt", "Sneaker", "Bag", "Ankle boot"], "names_file": null, "id": null, "_type": "ClassLabel"}}, "post_processed": null, "supervised_keys": {"input": "image", "output": "label"}, "builder_name": "fashion_mnist", "config_name": "fashion_mnist", "version": {"version_str": "1.0.0", "description": null, "major": 1, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 54480048, "num_examples": 60000, "dataset_name": "fashion_mnist"}, "test": {"name": "test", "num_bytes": 9080008, "num_examples": 10000, "dataset_name": "fashion_mnist"}}, "download_checksums": {"https://github.com/zalandoresearch/fashion-mnist/raw/master/data/fashion/train-images-idx3-ubyte.gz": {"num_bytes": 26421880, "checksum": "3aede38d61863908ad78613f6a32ed271626dd12800ba2636569512369268a84"}, "https://github.com/zalandoresearch/fashion-mnist/raw/master/data/fashion/train-labels-idx1-ubyte.gz": {"num_bytes": 29515, "checksum": "a04f17134ac03560a47e3764e11b92fc97de4d1bfaf8ba1a3aa29af54cc90845"}, "https://github.com/zalandoresearch/fashion-mnist/raw/master/data/fashion/t10k-images-idx3-ubyte.gz": {"num_bytes": 4422102, "checksum": "346e55b948d973a97e58d2351dde16a484bd415d4595297633bb08f03db6a073"}, "https://github.com/zalandoresearch/fashion-mnist/raw/master/data/fashion/t10k-labels-idx1-ubyte.gz": {"num_bytes": 5148, "checksum": "67da17c76eaffca5446c3361aaab5c3cd6d1c2608764d35dfb1850b086bf8dd5"}}, "download_size": 30878645, "post_processing_size": null, "dataset_size": 63560056, "size_in_bytes": 94438701}}
|
dummy/fashion_mnist/1.0.0/dummy_data.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ee22300f50880a2c21b923909c9f67b31a370b3f9be4670ab38a0f56956a7b99
|
3 |
+
size 5409
|
fashion_mnist.py
ADDED
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
|
3 |
+
#
|
4 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5 |
+
# you may not use this file except in compliance with the License.
|
6 |
+
# You may obtain a copy of the License at
|
7 |
+
#
|
8 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9 |
+
#
|
10 |
+
# Unless required by applicable law or agreed to in writing, software
|
11 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13 |
+
# See the License for the specific language governing permissions and
|
14 |
+
# limitations under the License.
|
15 |
+
|
16 |
+
# Lint as: python3
|
17 |
+
"""FashionMNIST Data Set"""
|
18 |
+
|
19 |
+
from __future__ import absolute_import, division, print_function
|
20 |
+
|
21 |
+
import struct
|
22 |
+
|
23 |
+
import numpy as np
|
24 |
+
|
25 |
+
import datasets
|
26 |
+
|
27 |
+
|
28 |
+
_CITATION = """\
|
29 |
+
@article{DBLP:journals/corr/abs-1708-07747,
|
30 |
+
author = {Han Xiao and
|
31 |
+
Kashif Rasul and
|
32 |
+
Roland Vollgraf},
|
33 |
+
title = {Fashion-MNIST: a Novel Image Dataset for Benchmarking Machine Learning
|
34 |
+
Algorithms},
|
35 |
+
journal = {CoRR},
|
36 |
+
volume = {abs/1708.07747},
|
37 |
+
year = {2017},
|
38 |
+
url = {http://arxiv.org/abs/1708.07747},
|
39 |
+
archivePrefix = {arXiv},
|
40 |
+
eprint = {1708.07747},
|
41 |
+
timestamp = {Mon, 13 Aug 2018 16:47:27 +0200},
|
42 |
+
biburl = {https://dblp.org/rec/bib/journals/corr/abs-1708-07747},
|
43 |
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
44 |
+
}
|
45 |
+
"""
|
46 |
+
|
47 |
+
_DESCRIPTION = """\
|
48 |
+
Fashion-MNIST is a dataset of Zalando's article images—consisting of a training set of
|
49 |
+
60,000 examples and a test set of 10,000 examples. Each example is a 28x28 grayscale image,
|
50 |
+
associated with a label from 10 classes. We intend Fashion-MNIST to serve as a direct drop-in
|
51 |
+
replacement for the original MNIST dataset for benchmarking machine learning algorithms.
|
52 |
+
It shares the same image size and structure of training and testing splits.
|
53 |
+
"""
|
54 |
+
|
55 |
+
_HOMEPAGE = "https://github.com/zalandoresearch/fashion-mnist"
|
56 |
+
_LICENSE = "https://raw.githubusercontent.com/zalandoresearch/fashion-mnist/master/LICENSE"
|
57 |
+
|
58 |
+
_URL = "https://github.com/zalandoresearch/fashion-mnist/raw/master/data/fashion/"
|
59 |
+
_URLS = {
|
60 |
+
"train_images": "train-images-idx3-ubyte.gz",
|
61 |
+
"train_labels": "train-labels-idx1-ubyte.gz",
|
62 |
+
"test_images": "t10k-images-idx3-ubyte.gz",
|
63 |
+
"test_labels": "t10k-labels-idx1-ubyte.gz",
|
64 |
+
}
|
65 |
+
|
66 |
+
|
67 |
+
class FashionMnist(datasets.GeneratorBasedBuilder):
|
68 |
+
"""FashionMNIST Data Set"""
|
69 |
+
|
70 |
+
BUILDER_CONFIGS = [
|
71 |
+
datasets.BuilderConfig(
|
72 |
+
name="fashion_mnist",
|
73 |
+
version=datasets.Version("1.0.0"),
|
74 |
+
description=_DESCRIPTION,
|
75 |
+
)
|
76 |
+
]
|
77 |
+
|
78 |
+
def _info(self):
|
79 |
+
return datasets.DatasetInfo(
|
80 |
+
description=_DESCRIPTION,
|
81 |
+
features=datasets.Features(
|
82 |
+
{
|
83 |
+
"image": datasets.Array2D(shape=(28, 28), dtype="uint8"),
|
84 |
+
"label": datasets.features.ClassLabel(
|
85 |
+
names=[
|
86 |
+
"T - shirt / top",
|
87 |
+
"Trouser",
|
88 |
+
"Pullover",
|
89 |
+
"Dress",
|
90 |
+
"Coat",
|
91 |
+
"Sandal",
|
92 |
+
"Shirt",
|
93 |
+
"Sneaker",
|
94 |
+
"Bag",
|
95 |
+
"Ankle boot",
|
96 |
+
]
|
97 |
+
),
|
98 |
+
}
|
99 |
+
),
|
100 |
+
supervised_keys=("image", "label"),
|
101 |
+
homepage="https://github.com/zalandoresearch/fashion-mnist",
|
102 |
+
citation=_CITATION,
|
103 |
+
)
|
104 |
+
|
105 |
+
def _split_generators(self, dl_manager):
|
106 |
+
urls_to_download = {key: _URL + fname for key, fname in _URLS.items()}
|
107 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
108 |
+
|
109 |
+
return [
|
110 |
+
datasets.SplitGenerator(
|
111 |
+
name=datasets.Split.TRAIN,
|
112 |
+
gen_kwargs={
|
113 |
+
"filepath": [downloaded_files["train_images"], downloaded_files["train_labels"]],
|
114 |
+
"split": "train",
|
115 |
+
},
|
116 |
+
),
|
117 |
+
datasets.SplitGenerator(
|
118 |
+
name=datasets.Split.TEST,
|
119 |
+
gen_kwargs={
|
120 |
+
"filepath": [downloaded_files["test_images"], downloaded_files["test_labels"]],
|
121 |
+
"split": "test",
|
122 |
+
},
|
123 |
+
),
|
124 |
+
]
|
125 |
+
|
126 |
+
def _generate_examples(self, filepath, split):
|
127 |
+
"""This function returns the examples in the raw form."""
|
128 |
+
# Images
|
129 |
+
with open(filepath[0], "rb") as f:
|
130 |
+
# First 16 bytes contain some metadata
|
131 |
+
_ = f.read(4)
|
132 |
+
size = struct.unpack(">I", f.read(4))[0]
|
133 |
+
_ = f.read(8)
|
134 |
+
images = np.frombuffer(f.read(), dtype=np.uint8).reshape(size, 28, 28)
|
135 |
+
|
136 |
+
# Labels
|
137 |
+
with open(filepath[1], "rb") as f:
|
138 |
+
# First 8 bytes contain some metadata
|
139 |
+
_ = f.read(8)
|
140 |
+
labels = np.frombuffer(f.read(), dtype=np.uint8)
|
141 |
+
|
142 |
+
for idx in range(size):
|
143 |
+
yield idx, {"image": images[idx], "label": int(labels[idx])}
|