Alibeigi commited on
Commit
42a37ed
1 Parent(s): fc04cf2

Upload zod.py

Browse files
Files changed (1) hide show
  1. zod.py +212 -0
zod.py ADDED
@@ -0,0 +1,212 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script
2
+ # contributor.
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
+ """ZOD dataset loading script."""
16
+
17
+ import csv
18
+ import json
19
+ import os
20
+
21
+ import datasets
22
+
23
+ _CITATION = """\
24
+ @article{,
25
+ title= {ZOD Frames},
26
+ journal= {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
27
+ author= {Mina Alibeigi and William Ljungbergh and Adam Tonderski and Georg Hess and Adam Lilja and Carl Lindstrom and Daria Motorniuk and Junsheng Fu and Jenny Widahl and Christoffer Petersson},
28
+ year= {2023},
29
+ url= {https://zod.zenseact.com/},
30
+ abstract= {Existing datasets for autonomous driving (AD) often lack diversity and long-range capabilities, focusing instead on 360◦ perception and temporal reasoning. To address this gap, we introduce ZOD, a large-scale and diverse multimodal dataset collected over two years in various European countries, covering an area 9× that of existing datasets. ZOD boasts the highest range and resolution sensors among comparable datasets, coupled with detailed keyframe annotations for 2D and 3D objects (up to 245m), road instance/semantic segmentation, traffic sign recognition, and road classification. We believe that this unique combination will facilitate breakthroughs in long-range perception and multi-task learning. The dataset is composed of Frames, Sequences, and Drives, designed to encompass both data diversity and support for spatio-temporal learning, sensor fusion, localization, and mapping. Frames consist of 100k curated camera images with two seconds of other supporting sensor data, while the 1473 Sequences and 29 Drives include the entire sensor suite for 20 seconds and a few minutes, respectively. ZOD is the only AD dataset released under the permissive CC BY-SA 4.0 license, allowing for both research and commercial use. More information, and an extensive devkit, can be found at zod.zenseact.com.},
31
+ keywords= {Computer Vision, autonomous driving, object detection, semantic segmentation, traffic sign classification},
32
+ license= {CC BY-SA},
33
+ terms= {},
34
+ superseded= {}"""
35
+
36
+ _DESCRIPTION = """\
37
+ The Zenseact Open Dataset (ZOD) is a large multi-modal autonomous driving (AD) dataset, created by researchers at Zenseact. It was collected over a 2-year period in 14 different European counties, using a fleet of vehicles equipped with a full sensor suite. The dataset consists of three subsets: Frames, Sequences, and Drives, designed to encompass both data diversity and support for spatiotemporal learning, sensor fusion, localization, and mapping. Together with the data, we have developed a SDK containing tutorials, downloading functionality, and a dataset API for easy access to the data. The development kit is available on Github.
38
+ """
39
+
40
+ _HOMEPAGE = "https://zod.zenseact.com/"
41
+
42
+ _LICENSE = """
43
+ The Zenseact Open Dataset (ZOD) is the property of Zenseact AB (© 2022 Zenseact AB) and is licensed under the permissive CC BY-SA. Any public use, distribution, or display of this dataset must contain this entire notice:
44
+
45
+ For this dataset, Zenseact AB has taken all reasonable measures to remove all personally identifiable information, including faces and license plates. To the extent that you like to request removal of specific images from the dataset, please contact privacy@zenseact.com.
46
+ """
47
+
48
+
49
+ _URLS = {
50
+ "first_domain": None,
51
+ "second_domain": None,
52
+ }
53
+
54
+
55
+ class ZODDataset(datasets.GeneratorBasedBuilder):
56
+ """Zenseact Open Dataset (ZOD) is a large-scale and diverse multimodal autonomous
57
+ driving dataset collected over two years in various European countries. It
58
+ contains a wide range of traffic scenarios of real-world driving, collected under
59
+ different weather and lighting conditions.
60
+
61
+ ZOD contains a significant number of high-quality and detailed annotations for
62
+ several perception tasks."""
63
+
64
+ VERSION = datasets.Version("2.0.0")
65
+
66
+ # This is an example of a dataset with multiple configurations.
67
+ # If you don't want/need to define several sub-sets in your dataset,
68
+ # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
69
+
70
+ # If you need to make complex sub-parts in the datasets with configurable options
71
+ # You can create your own builder configuration class to store attribute,
72
+ # inheriting from datasets.BuilderConfig
73
+ # BUILDER_CONFIG_CLASS = MyBuilderConfig
74
+
75
+ # You will be able to load one or the other configurations in the following list
76
+ # with
77
+ # data = datasets.load_dataset('my_dataset', 'first_domain')
78
+ # data = datasets.load_dataset('my_dataset', 'second_domain')
79
+ BUILDER_CONFIGS = [
80
+ datasets.BuilderConfig(name="mini", version=VERSION,
81
+ description="Mini version"),
82
+ # In future, here's a place for more configurations
83
+ # datasets.BuilderConfig(name="second_domain", version=VERSION,
84
+ # description="This part of my dataset covers a second domain"),
85
+ ]
86
+
87
+ def _info(self):
88
+ if self.config.name == "mini": # This is the name of the
89
+ # configuration selected in BUILDER_CONFIGS above
90
+ features = datasets.Features(
91
+ {
92
+ "id": datasets.Value("string"),
93
+ "camera_frames":
94
+ {'front_blur': datasets.Sequence(
95
+ feature={
96
+ 'image': datasets.Image(decode=True),
97
+ 'time': datasets.Value("string"),
98
+ 'height': datasets.Value("int32"),
99
+ 'width': datasets.Value("int32"),
100
+ },
101
+ length=-1),
102
+ 'front_dnat': datasets.Sequence(
103
+ feature={
104
+ 'image': datasets.Image(decode=True),
105
+ 'time': datasets.Value("string"),
106
+ 'height': datasets.Value("int32"),
107
+ 'width': datasets.Value("int32"),
108
+ },
109
+ length=-1),
110
+ },
111
+ "road_condition": {
112
+ "wetness": datasets.Value("bool"),
113
+ "snow_coverage": datasets.Value("bool"),
114
+ },
115
+ }
116
+ )
117
+
118
+ return datasets.DatasetInfo(
119
+ # This is the description that will appear on the datasets page.
120
+ description=_DESCRIPTION,
121
+ # This defines the different columns of the dataset and their types
122
+ features=features,
123
+ # Here we define them above because they are different between the
124
+ # two configurations
125
+ # If there's a common (input, target) tuple from the features,
126
+ # uncomment supervised_keys line below and
127
+ # specify them. They'll be used if as_supervised=True in
128
+ # builder.as_dataset.
129
+ # supervised_keys=("sentence", "label"),
130
+ # Homepage of the dataset for documentation
131
+ homepage=_HOMEPAGE,
132
+ license=_LICENSE,
133
+ citation=_CITATION,
134
+ )
135
+
136
+ def _split_generators(self, dl_manager):
137
+ # If several configurations are possible (listed in BUILDER_CONFIGS),
138
+ # the configuration selected by the user is in self.config.name
139
+
140
+ data_dir = dl_manager.manual_dir
141
+ return [
142
+ datasets.SplitGenerator(
143
+ name=datasets.Split.TRAIN,
144
+ # These kwargs will be passed to _generate_examples
145
+ gen_kwargs={
146
+ "data_dir": data_dir,
147
+ "metadata_path":
148
+ os.path.join(data_dir, "trainval-frames-mini.json"),
149
+ "split": "train",
150
+ },
151
+ ),
152
+ datasets.SplitGenerator(
153
+ name=datasets.Split.VALIDATION,
154
+ # These kwargs will be passed to _generate_examples
155
+ gen_kwargs={
156
+ "data_dir": data_dir,
157
+ "metadata_path":
158
+ os.path.join(data_dir, "trainval-frames-mini.json"),
159
+ "split": "val",
160
+ },
161
+ ),
162
+ ]
163
+
164
+ # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
165
+ def _generate_examples(self, data_dir, metadata_path, split):
166
+ if not os.path.exists(data_dir):
167
+ raise FileNotFoundError(
168
+ f"{data_dir} does not exist."
169
+ f"{self.manual_download_instructions}"
170
+ )
171
+ with open(metadata_path, "r") as f:
172
+ all_metadata = json.load(f)
173
+ split_metadata = all_metadata[split]
174
+ for sample_metadata in split_metadata:
175
+ annotations_keys = list(sample_metadata["annotations"].keys())
176
+ annotations_dict = {}
177
+ for annotations_key in annotations_keys:
178
+ annot_part_path = sample_metadata["annotations"][annotations_key]["filepath"]
179
+ annot_full_path = os.path.join(data_dir, annot_part_path)
180
+ with open(annot_full_path) as f:
181
+ annotations = json.load(f)
182
+ annotations_dict[annotations_key] = annotations
183
+
184
+ # create image
185
+ camera_frames = sample_metadata["camera_frames"]
186
+ list_of_frames = camera_frames["front_blur"]
187
+ for camera_frame in list_of_frames:
188
+ camera_frame["image"] = os.path.join(data_dir, camera_frame["filepath"])
189
+ camera_frame.pop("filepath")
190
+ list_of_frames = camera_frames["front_dnat"]
191
+ for camera_frame in list_of_frames:
192
+ camera_frame["image"] = os.path.join(data_dir, camera_frame["filepath"])
193
+ camera_frame.pop("filepath")
194
+
195
+ yield sample_metadata["id"], {
196
+ "id": sample_metadata["id"],
197
+ "camera_frames": {**camera_frames},
198
+ "road_condition": {**annotations_dict["road_condition"]},
199
+ }
200
+
201
+ @property
202
+ def manual_download_instructions(self):
203
+ return ("To use ZOD dataset you have to download it manually, then pass the "
204
+ "path to the data_dir parameter of load_dataset.\n"
205
+ "Please send your request based on the information on this website: "
206
+ "https://zod.zenseact.com/download/. "
207
+ "You will receive a download link after your application is approved."
208
+ "We recommend utilizing the CLI tool from our development kit for a smoother download experience."
209
+ "Full instructions can be found in the devkit README available at https://github.com/zenseact/zod."
210
+ "Finally load the dataset in the following way\n"
211
+ "`datasets.load_dataset('Zenseact/ZOD', config-name, data_dir=data-dir)`")
212
+