Datasets:
Tasks:
Image Classification
Sub-tasks:
multi-class-image-classification
Languages:
English
Size:
10K<n<100K
ArXiv:
License:
yourusername
commited on
Commit
•
39cc14c
1
Parent(s):
f431bc5
add fairface.py
Browse files- fairface.py +53 -0
fairface.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pathlib import Path
|
2 |
+
from typing import List
|
3 |
+
import datasets
|
4 |
+
import pickle
|
5 |
+
|
6 |
+
logger = datasets.logging.get_logger(__name__)
|
7 |
+
|
8 |
+
|
9 |
+
class Fairface(datasets.GeneratorBasedBuilder):
|
10 |
+
|
11 |
+
_HOMEPAGE = "https://huggingface.co/datasets/nateraw/fairface/"
|
12 |
+
_URL = "https://huggingface.co/datasets/nateraw/fairface/raw/main/"
|
13 |
+
_URLS = {
|
14 |
+
"train": _URL + "train.pt",
|
15 |
+
"dev": _URL + "val.pt",
|
16 |
+
}
|
17 |
+
_DESCRIPTION = "The Fairface dataset"
|
18 |
+
_CITATION = None
|
19 |
+
|
20 |
+
def _info(self):
|
21 |
+
return datasets.DatasetInfo(
|
22 |
+
description=self._DESCRIPTION,
|
23 |
+
features=datasets.Features(
|
24 |
+
{
|
25 |
+
'img_bytes': datasets.Value('binary'),
|
26 |
+
'age': datasets.features.ClassLabel(names=['0-2', '3-9', '10-19', '20-29', '30-39', '40-49', '50-59', '60-69', 'more than 70']),
|
27 |
+
"gender": datasets.features.ClassLabel(names=['Female', 'Male']),
|
28 |
+
'race': datasets.features.ClassLabel(names=['Black', 'East Asian', 'Indian', 'Latino_Hispanic', 'Middle Eastern', 'Southeast Asian', 'White'])
|
29 |
+
}
|
30 |
+
),
|
31 |
+
supervised_keys=('img_bytes', 'age'),
|
32 |
+
homepage=self._HOMEPAGE,
|
33 |
+
citation=self._CITATION,
|
34 |
+
)
|
35 |
+
|
36 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
37 |
+
downloaded_files = dl_manager.download_and_extract(self._URLS)
|
38 |
+
return [
|
39 |
+
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
40 |
+
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]})
|
41 |
+
]
|
42 |
+
|
43 |
+
def _generate_examples(self, filepath):
|
44 |
+
"""This function returns the examples in the raw (text) form."""
|
45 |
+
logger.info("generating examples from = %s", filepath)
|
46 |
+
|
47 |
+
with Path(filepath).open('rb') as f:
|
48 |
+
examples = pickle.load(f)
|
49 |
+
|
50 |
+
for i, ex in enumerate(examples):
|
51 |
+
print(ex)
|
52 |
+
_id = ex.pop('_id')
|
53 |
+
yield _id, ex
|