File size: 13,704 Bytes
1f987aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f7109ba
1f987aa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# coding=utf-8
# Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""VALERIE22 dataset"""

import os
import json     
import glob

import datasets


_HOMEPAGE = "https://huggingface.co/datasets/Intel/VALERIE22"

_LICENSE = "Creative Commons — CC0 1.0 Universal"

_CITATION = """\
tba
"""

_DESCRIPTION = """\
The VALERIE22 dataset was generated with the VALERIE procedural tools pipeline providing a photorealistic sensor simulation rendered from automatically synthesized scenes. The dataset provides a uniquely rich set of metadata, allowing extraction of specific scene and semantic features (like pixel-accurate occlusion rates, positions in the scene and distance + angle to the camera). This enables a multitude of possible tests on the data and we hope to stimulate research on understanding performance of DNNs.
"""

_REPO = "https://huggingface.co/datasets/Intel/VALERIE22/resolve/main"

_SEQUENCES = {
    "train": ["intel_results_sequence_0057.zip", "intel_results_sequence_0058.zip", "intel_results_sequence_0059.zip", "intel_results_sequence_0060.zip", "intel_results_sequence_0062_part1.zip", "intel_results_sequence_0062_part2.zip"],
    "validation":["intel_results_sequence_0062_part1.zip", "intel_results_sequence_0062_part2.zip"],
    "test":["intel_results_sequence_0062_part1.zip", "intel_results_sequence_0062_part2.zip"]
              }

_URLS = {
    "train": [f"{_REPO}/data/{sequence}" for sequence in _SEQUENCES["train"]],
    "validation": [f"{_REPO}/data/{sequence}" for sequence in _SEQUENCES["validation"]],
    "test": [f"{_REPO}/data/{sequence}" for sequence in _SEQUENCES["test"]]
}

class VALERIE22(datasets.GeneratorBasedBuilder):
    """VALERIE22 dataset."""

    VERSION = datasets.Version("1.0.0")

    def _info(self):
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=datasets.Features(
                {
                    "image": datasets.Image(),
                    "image_distorted": datasets.Image(),
                    "persons_png": datasets.Sequence(
                        {
                            "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
                            "bbox_vis": datasets.Sequence(datasets.Value("float32"), length=4),
                            "occlusion": datasets.Value("float32"),
                            "distance": datasets.Value("float32"),
                            "v_x": datasets.Value("float32"),
                            "v_y": datasets.Value("float32"),
                            "truncated": datasets.Value("bool"),
                            "total_pixels_object": datasets.Value("float32"),
                            "total_visible_pixels_object": datasets.Value("float32"),
                            "contrast_rgb_full": datasets.Value("float32"),
                            "contrast_edge": datasets.Value("float32"),
                            "contrast_rgb": datasets.Value("float32"),
                            "luminance": datasets.Value("float32"),
                            "perceived_lightness": datasets.Value("float32"),
                            "3dbbox": datasets.Sequence(datasets.Value("float32"), length=6) # 3center, 3 size
                        }
                    ),
                    "persons_png_distorted": datasets.Sequence(
                        {
                            "bbox": datasets.Sequence(datasets.Value("float32"), length=4),
                            "bbox_vis": datasets.Sequence(datasets.Value("float32"), length=4),
                            "occlusion": datasets.Value("float32"),
                            "distance": datasets.Value("float32"),
                            "v_x": datasets.Value("float32"),
                            "v_y": datasets.Value("float32"),
                            "truncated": datasets.Value("bool"),
                            "total_pixels_object": datasets.Value("float32"),
                            "total_visible_pixels_object": datasets.Value("float32"),
                            "contrast_rgb_full": datasets.Value("float32"),
                            "contrast_edge": datasets.Value("float32"),
                            "contrast_rgb": datasets.Value("float32"),
                            "luminance": datasets.Value("float32"),
                            "perceived_lightness": datasets.Value("float32"),
                            "3dbbox": datasets.Sequence(datasets.Value("float32"), length=6) # 3center, 3 size
                        }
                    ),
                    "semantic_group_segmentation": datasets.Image(),
                    "semantic_instance_segmentation": datasets.Image()                    
                }
            ),
            supervised_keys=None,
            homepage=_HOMEPAGE,
            license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        data_dir = dl_manager.download_and_extract(_URLS)
        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "split": "train",
                    "data_dirs": data_dir["train"],
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.TEST,
                gen_kwargs={
                    "split": "test",
                    "data_dirs": data_dir["test"],
                },
            ),
            datasets.SplitGenerator(
                name=datasets.Split.VALIDATION,
                gen_kwargs={
                    "split": "validation",
                    "data_dirs": data_dir["validation"],
                },
            ),
        ]

    def _generate_examples(self, split, data_dirs):
        sequence_dirs = []
        for data_dir, sequence in zip(data_dirs, _SEQUENCES[split]):
            sequence = sequence.replace(".zip","")
            if "_part1" in sequence:
                sequence = sequence.replace("_part1","")
            if "_part2" in sequence:
                sequence_0062_part2_dir = os.path.join(data_dir, sequence.replace("_part2","_b"))
                continue
            sequence_dirs.append(os.path.join(data_dir, sequence))

        idx = 0
        for sequence_dir in sequence_dirs:
            for filename in glob.glob(os.path.join(os.path.join(sequence_dir, "sensor/camera/left/png"), "*.png")):        
                # image_file_path
                image_file_path = filename

                # image_distorted_file_path
                if "_0062" in sequence_dir:
                    image_distorted_file_path = os.path.join(sequence_0062_part2_dir, "sensor/camera/left/png_distorted/", os.path.basename(filename))
                else:
                    image_distorted_file_path = filename.replace("/png/", "/png_distorted/")

                #persons_png
                persons_png_path = filename.replace("sensor/camera/left/png/", "ground-truth/2d-bounding-box_json/")

                #persons_distorted_png
                persons_distorted_png_path = filename.replace("sensor/camera/left/png/", "ground-truth/2d-bounding-box_json_png_distorted/")

                #semantic_group_segmentation_file_path
                semantic_group_segmentation_file_path = filename.replace("sensor/camera/left/png/", "ground-truth/semantic-group-segmentation_png/")

                # semantic_instance_segmentation_file_path
                semantic_instance_segmentation_file_path = filename.replace("sensor/camera/left/png/", "ground-truth/semantic-instance-segmentation_png/")

                # check if all gt files are available
                if not (os.path.isfile(image_file_path) and os.path.isfile(image_distorted_file_path) and os.path.isfile(persons_png_path.replace(".png",".json")) and os.path.isfile(persons_distorted_png_path.replace(".png",".json")) and os.path.isfile(semantic_group_segmentation_file_path) and os.path.isfile(semantic_instance_segmentation_file_path)):
                    continue

                with open(persons_png_path.replace(".png",".json"), 'r') as json_file:
                    bb_person_json = json.load(json_file)

                with open(persons_distorted_png_path.replace(".png",".json"), 'r') as json_file:
                    bb_person_distorted_json = json.load(json_file)

                threed_bb_person_path = filename.replace("sensor/camera/left/png/", "ground-truth/3d-bounding-box_json/")
                with open(os.path.join(threed_bb_person_path.replace(".png",".json")), 'r') as json_file:
                    threed_bb_person_distorted_json = json.load(json_file)                        

                persons_png = []
                persons_png_distorted = []
                for key in bb_person_json:
                    persons_png.append(
                        {
                            "bbox": [bb_person_json[key]["bb"]["c_x"], bb_person_json[key]["bb"]["c_y"], bb_person_json[key]["bb"]["w"], bb_person_json[key]["bb"]["h"]],
                            "bbox_vis": [bb_person_json[key]["bb_vis"]["c_x"], bb_person_json[key]["bb_vis"]["c_y"], bb_person_json[key]["bb_vis"]["w"], bb_person_json[key]["bb_vis"]["h"]],
                            "occlusion": bb_person_json[key]["occlusion"],
                            "distance": bb_person_json[key]["distance"],
                            "v_x": bb_person_json[key]["v_x"],
                            "v_y": bb_person_json[key]["v_y"],
                            "truncated": bb_person_json[key]["truncated"],
                            "total_pixels_object": bb_person_json[key]["total_pixels_object"],
                            "total_visible_pixels_object": bb_person_json[key]["total_visible_pixels_object"],
                            "contrast_rgb_full": bb_person_json[key]["contrast_rgb_full"],
                            "contrast_edge": bb_person_json[key]["contrast_edge"],
                            "contrast_rgb": bb_person_json[key]["contrast_rgb"],
                            "luminance": bb_person_json[key]["luminance"],
                            "perceived_lightness": bb_person_json[key]["perceived_lightness"],
                            "3dbbox": [threed_bb_person_distorted_json[key]["center"][0], threed_bb_person_distorted_json[key]["center"][1], threed_bb_person_distorted_json[key]["center"][2], threed_bb_person_distorted_json[key]["size"][0],
                                threed_bb_person_distorted_json[key]["size"][1], threed_bb_person_distorted_json[key]["size"][2]] # 3center, 3 size
                        }
                    )
                    
                    persons_png_distorted.append(
                        {
                            "bbox": [bb_person_distorted_json[key]["bb"]["c_x"], bb_person_distorted_json[key]["bb"]["c_y"], bb_person_distorted_json[key]["bb"]["w"], bb_person_distorted_json[key]["bb"]["h"]],
                            "bbox_vis": [bb_person_distorted_json[key]["bb_vis"]["c_x"], bb_person_distorted_json[key]["bb_vis"]["c_y"], bb_person_distorted_json[key]["bb_vis"]["w"], bb_person_distorted_json[key]["bb_vis"]["h"]],
                            "occlusion": bb_person_distorted_json[key]["occlusion"],
                            "distance": bb_person_distorted_json[key]["distance"],
                            "v_x": bb_person_distorted_json[key]["v_x"],
                            "v_y": bb_person_distorted_json[key]["v_y"],
                            "truncated": bb_person_distorted_json[key]["truncated"],
                            "total_pixels_object": bb_person_distorted_json[key]["total_pixels_object"],
                            "total_visible_pixels_object": bb_person_distorted_json[key]["total_visible_pixels_object"],
                            "contrast_rgb_full": bb_person_distorted_json[key]["contrast_rgb_full"],
                            "contrast_edge": bb_person_distorted_json[key]["contrast_edge"],
                            "contrast_rgb": bb_person_distorted_json[key]["contrast_rgb"],
                            "luminance": bb_person_distorted_json[key]["luminance"],
                            "perceived_lightness": bb_person_distorted_json[key]["perceived_lightness"],
                            "3dbbox": [threed_bb_person_distorted_json[key]["center"][0], threed_bb_person_distorted_json[key]["center"][1], threed_bb_person_distorted_json[key]["center"][2], threed_bb_person_distorted_json[key]["size"][0],
                                threed_bb_person_distorted_json[key]["size"][1], threed_bb_person_distorted_json[key]["size"][2]] # 3center, 3 size
                        }
                    )                        

                yield idx, {"image": image_file_path, "image_distorted": image_distorted_file_path, "persons_png": persons_png, "persons_png_distorted":persons_png_distorted, "semantic_group_segmentation": semantic_group_segmentation_file_path, "semantic_instance_segmentation": semantic_instance_segmentation_file_path}
                idx += 1