Skip to content

Commit cc492b4

Browse files
committed
created wake vision dataset builder
1 parent c0a39db commit cc492b4

File tree

2 files changed

+94
-16
lines changed

2 files changed

+94
-16
lines changed

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@
188188
'smartwatch_gestures': ['pandas'],
189189
'svhn': ['scipy'],
190190
'the300w_lp': ['scipy'],
191+
'wake_vision': ['pandas'],
191192
'wider_face': ['Pillow'],
192193
'wiki_dialog': ['apache-beam'],
193194
'wikipedia': ['apache-beam', 'mwparserfromhell', 'mwxml'],

tensorflow_datasets/image_classification/wake_vision/wake_vision_dataset_builder.py

Lines changed: 93 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,123 @@
22

33
import tensorflow_datasets.public_api as tfds
44

5+
_TRAIN_IMAGE_IDS = [9270406, 9270356, 9270408, 9270367, 9270349, 9270351, 9270390, 9270375, 9270387, 9270370, 9270396, 9270340, 9270411, 9270369, 9270357, 9270378, 9270386, 9270376, 9270341, 9270392, 9270334, 9270404, 9270330, 9270321, 9270364, 9270380, 9270343, 9270335, 9270412, 9270362, 9270339, 9270331, 9270399, 9270410, 9270393, 9270325, 9270346, 9270337, 9270391, 9270361, 9270363, 9270372, 9270326, 9270322, 9270329, 9270381, 9270338, 9270397, 9270405, 9270379, 9270352, 9270400, 9270384, 9270383, 9270388, 9270324, 9270407, 9270348, 9270347, 9270371, 9270358, 9270350, 9270323, 9270401, 9270368, 9270360, 9270328, 9270327, 9270382, 9270332, 9270394, 9270409, 9270345, 9270342, 9270353, 9270403, 9270398, 9270402, 9270395, 9270333, 9270373, 9270336, 9270385, 9270320, 9270366, 9270374, 9270377, 9270354, 9270344, 9270359]
6+
7+
_URLS = {
8+
'train_images': [
9+
tfds.download.Resource(
10+
url=f'https://dataverse.harvard.edu/api/access/datafile/{id}?format=original',
11+
extract_method=tfds.download.ExtractMethod.GZIP,
12+
)
13+
for id in _TRAIN_IMAGE_IDS
14+
],
15+
'validation_images': tfds.download.Resource(
16+
url='https://dataverse.harvard.edu/api/access/datafile/9270355?format=original',
17+
extract_method=tfds.download.ExtractMethod.GZIP,
18+
),
19+
'test_images': tfds.download.Resource(
20+
url='https://dataverse.harvard.edu/api/access/datafile/9270389?format=original',
21+
extract_method=tfds.download.ExtractMethod.GZIP,
22+
),
23+
'train_image_metadata': 'https://dataverse.harvard.edu/api/access/datafile/9844933?format=original',
24+
'train_bbox_metadata': 'https://dataverse.harvard.edu/api/access/datafile/9844934?format=original',
25+
'validation_metadata': 'https://dataverse.harvard.edu/api/access/datafile/9844936?format=original',
26+
'test_metadata': 'https://dataverse.harvard.edu/api/access/datafile/9844935?format=original',
27+
}
528

629
class Builder(tfds.core.GeneratorBasedBuilder):
730
"""DatasetBuilder for wake_vision dataset."""
831

932
VERSION = tfds.core.Version('1.0.0')
1033
RELEASE_NOTES = {
11-
'1.0.0': 'Initial release.',
34+
'1.0.0': 'Initial TensorFlow Datasets release. Note that this is based on the 2.0 version of Wake Vision on Harvard Dataverse.',
1235
}
1336

1437
def _info(self) -> tfds.core.DatasetInfo:
1538
"""Returns the dataset metadata."""
16-
# TODO(wake_vision): Specifies the tfds.core.DatasetInfo object
1739
return self.dataset_info_from_configs(
40+
description=
41+
"""
42+
The Wake Vision dataset for person detection.
43+
44+
The dataset contains images with annotations of whether each image contains a person. Additional annotations about perceived gender, perceived age, subject distance, lighting conditions, depictions, and specific body parts are also available for some subsets of the dataset.
45+
46+
We publish the annotations of this dataset under a CC BY 4.0 license. All images in the dataset are from the Open Images v7 dataset, which sourced images from Flickr listed as having a CC BY 2.0 license.
47+
"""
48+
,
1849
features=tfds.features.FeaturesDict({
1950
# These are the features of your dataset like images, labels ...
2051
'image': tfds.features.Image(shape=(None, None, 3)),
21-
'label': tfds.features.ClassLabel(names=['no', 'yes']),
52+
'filename': tfds.features.Text(),
53+
'person': tfds.features.ClassLabel(names=['No', 'Yes']),
54+
'depiction': tfds.features.ClassLabel(names=['No', 'Yes']),
55+
'body_part': tfds.features.ClassLabel(names=['No', 'Yes']),
56+
'predominantly_female': tfds.features.ClassLabel(names=['No', 'Yes']),
57+
'predominantly_male': tfds.features.ClassLabel(names=['No', 'Yes']),
58+
'gender_unknown': tfds.features.ClassLabel(names=['No', 'Yes']),
59+
'young': tfds.features.ClassLabel(names=['No', 'Yes']),
60+
'middle_age': tfds.features.ClassLabel(names=['No', 'Yes']),
61+
'older': tfds.features.ClassLabel(names=['No', 'Yes']),
62+
'age_unknown': tfds.features.ClassLabel(names=['No', 'Yes']),
63+
'near': tfds.features.ClassLabel(names=['No', 'Yes']),
64+
'medium_distance': tfds.features.ClassLabel(names=['No', 'Yes']),
65+
'far': tfds.features.ClassLabel(names=['No', 'Yes']),
66+
'dark': tfds.features.ClassLabel(names=['No', 'Yes']),
67+
'normal_lighting': tfds.features.ClassLabel(names=['No', 'Yes']),
68+
'bright': tfds.features.ClassLabel(names=['No', 'Yes']),
69+
'person_depiction': tfds.features.ClassLabel(names=['No', 'Yes']),
70+
'non-person_depiction': tfds.features.ClassLabel(names=['No', 'Yes']),
71+
'non-person_non-depiction': tfds.features.ClassLabel(names=['No', 'Yes']),
2272
}),
2373
# If there's a common (input, target) tuple from the
2474
# features, specify them here. They'll be used if
2575
# `as_supervised=True` in `builder.as_dataset`.
26-
supervised_keys=('image', 'label'), # Set to `None` to disable
27-
homepage='https://dataset-homepage/',
76+
supervised_keys=('image', 'person'), # Set to `None` to disable
77+
homepage='https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi%3A10.7910%2FDVN%2F1HOPXC',
78+
license='See homepage for license information.',
2879
)
2980

3081
def _split_generators(self, dl_manager: tfds.download.DownloadManager):
3182
"""Returns SplitGenerators."""
32-
# TODO(wake_vision): Downloads the data and defines the splits
33-
path = dl_manager.download_and_extract('https://todo-data-url')
83+
paths = dl_manager.download_and_extract(_URLS)
3484

35-
# TODO(wake_vision): Returns the Dict[split names, Iterator[Key, Example]]
3685
return {
37-
'train': self._generate_examples(path / 'train_imgs'),
86+
'train_image': self._generate_examples(paths['train_images'], paths['train_image_metadata']),
87+
'train_bbox': self._generate_examples(paths['train_images'], paths['train_bbox_metadata']),
88+
'validation' : self._generate_examples(paths['validation_images'], paths['validation_metadata']),
89+
'test' : self._generate_examples(paths['test_images'], paths['test_metadata']),
3890
}
3991

40-
def _generate_examples(self, path):
92+
def _generate_examples(self, image_paths, metadata_path):
4193
"""Yields examples."""
42-
# TODO(wake_vision): Yields (key, example) tuples from the dataset
43-
for f in path.glob('*.jpeg'):
44-
yield 'key', {
45-
'image': f,
46-
'label': 'yes',
47-
}
94+
metadata = tfds.core.lazy_imports.pandas.read_csv(metadata_path, index_col='filename')
95+
96+
for tar_file in image_paths:
97+
for sample_path, sample_object in tfds.download.iter_archive(tar_file, tfds.download.ExtractMethod.TAR_STREAM):
98+
file_name = sample_path
99+
100+
sample_metadata = metadata.loc[file_name]
101+
102+
yield file_name, {
103+
'image': sample_object,
104+
'filename': file_name,
105+
'person': sample_metadata['person'],
106+
'depiction': sample_metadata['depiction'],
107+
'body_part': sample_metadata['body_part'],
108+
'predominantly_female': sample_metadata['predominantly_female'],
109+
'predominantly_male': sample_metadata['predominantly_male'],
110+
'gender_unknown': sample_metadata['gender_unknown'],
111+
'young': sample_metadata['young'],
112+
'middle_age': sample_metadata['middle_age'],
113+
'older': sample_metadata['older'],
114+
'age_unknown': sample_metadata['age_unknown'],
115+
'near': sample_metadata['near'],
116+
'medium_distance': sample_metadata['medium_distance'],
117+
'far': sample_metadata['far'],
118+
'dark': sample_metadata['dark'],
119+
'normal_lighting': sample_metadata['normal_lighting'],
120+
'bright': sample_metadata['bright'],
121+
'person_depiction': sample_metadata['person_depiction'],
122+
'non-person_depiction': sample_metadata['non-person_depiction'],
123+
'non-person_non-depiction': sample_metadata['non-person_non-depiction'],
124+
}

0 commit comments

Comments
 (0)