ZOD / ZOD.py
Alibeigi's picture
Rename zod.py to ZOD.py
8962451 verified
# 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.
"""ZOD dataset loading script."""
import csv
import json
import os
import datasets
_CITATION = """\
@article{,
title= {ZOD Frames},
journal= {Proceedings of the IEEE/CVF International Conference on Computer Vision (ICCV)},
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},
year= {2023},
url= {https://zod.zenseact.com/},
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.},
keywords= {Computer Vision, autonomous driving, object detection, semantic segmentation, traffic sign classification},
license= {CC BY-SA},
terms= {},
superseded= {}"""
_DESCRIPTION = """\
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.
"""
_HOMEPAGE = "https://zod.zenseact.com/"
_LICENSE = """
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:
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 [email protected].
"""
_URLS = {
"first_domain": None,
"second_domain": None,
}
class ZODDataset(datasets.GeneratorBasedBuilder):
"""Zenseact Open Dataset (ZOD) is a large-scale and diverse multimodal autonomous
driving dataset collected over two years in various European countries. It
contains a wide range of traffic scenarios of real-world driving, collected under
different weather and lighting conditions.
ZOD contains a significant number of high-quality and detailed annotations for
several perception tasks."""
VERSION = datasets.Version("2.0.0")
# This is an example of a dataset with multiple configurations.
# If you don't want/need to define several sub-sets in your dataset,
# just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.
# If you need to make complex sub-parts in the datasets with configurable options
# You can create your own builder configuration class to store attribute,
# inheriting from datasets.BuilderConfig
# BUILDER_CONFIG_CLASS = MyBuilderConfig
# You will be able to load one or the other configurations in the following list
# with
# data = datasets.load_dataset('my_dataset', 'first_domain')
# data = datasets.load_dataset('my_dataset', 'second_domain')
BUILDER_CONFIGS = [
datasets.BuilderConfig(name="mini", version=VERSION,
description="Mini version"),
# In future, here's a place for more configurations
# datasets.BuilderConfig(name="second_domain", version=VERSION,
# description="This part of my dataset covers a second domain"),
]
def _info(self):
if self.config.name == "mini": # This is the name of the
# configuration selected in BUILDER_CONFIGS above
features = datasets.Features(
{
"id": datasets.Value("string"),
"camera_frames":
{'front_blur': datasets.Sequence(
feature={
'image': datasets.Image(decode=True),
'time': datasets.Value("string"),
'height': datasets.Value("int32"),
'width': datasets.Value("int32"),
},
length=-1),
'front_dnat': datasets.Sequence(
feature={
'image': datasets.Image(decode=True),
'time': datasets.Value("string"),
'height': datasets.Value("int32"),
'width': datasets.Value("int32"),
},
length=-1),
},
"road_condition": {
"wetness": datasets.Value("bool"),
"snow_coverage": datasets.Value("bool"),
},
}
)
return datasets.DatasetInfo(
# This is the description that will appear on the datasets page.
description=_DESCRIPTION,
# This defines the different columns of the dataset and their types
features=features,
# Here we define them above because they are different between the
# two configurations
# If there's a common (input, target) tuple from the features,
# uncomment supervised_keys line below and
# specify them. They'll be used if as_supervised=True in
# builder.as_dataset.
# supervised_keys=("sentence", "label"),
# Homepage of the dataset for documentation
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
# If several configurations are possible (listed in BUILDER_CONFIGS),
# the configuration selected by the user is in self.config.name
data_dir = dl_manager.manual_dir
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"data_dir": data_dir,
"metadata_path":
os.path.join(data_dir, "trainval-frames-mini.json"),
"split": "train",
},
),
datasets.SplitGenerator(
name=datasets.Split.VALIDATION,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"data_dir": data_dir,
"metadata_path":
os.path.join(data_dir, "trainval-frames-mini.json"),
"split": "val",
},
),
]
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
def _generate_examples(self, data_dir, metadata_path, split):
if not os.path.exists(data_dir):
raise FileNotFoundError(
f"{data_dir} does not exist."
f"{self.manual_download_instructions}"
)
with open(metadata_path, "r") as f:
all_metadata = json.load(f)
split_metadata = all_metadata[split]
for sample_metadata in split_metadata:
annotations_keys = list(sample_metadata["annotations"].keys())
annotations_dict = {}
for annotations_key in annotations_keys:
annot_part_path = sample_metadata["annotations"][annotations_key]["filepath"]
annot_full_path = os.path.join(data_dir, annot_part_path)
with open(annot_full_path) as f:
annotations = json.load(f)
annotations_dict[annotations_key] = annotations
# create image
camera_frames = sample_metadata["camera_frames"]
list_of_frames = camera_frames["front_blur"]
for camera_frame in list_of_frames:
camera_frame["image"] = os.path.join(data_dir, camera_frame["filepath"])
camera_frame.pop("filepath")
list_of_frames = camera_frames["front_dnat"]
for camera_frame in list_of_frames:
camera_frame["image"] = os.path.join(data_dir, camera_frame["filepath"])
camera_frame.pop("filepath")
yield sample_metadata["id"], {
"id": sample_metadata["id"],
"camera_frames": {**camera_frames},
"road_condition": {**annotations_dict["road_condition"]},
}
@property
def manual_download_instructions(self):
return ("To use ZOD dataset you have to download it manually, then pass the "
"path to the data_dir parameter of load_dataset.\n"
"Please send your request based on the information on this website: "
"https://zod.zenseact.com/download/. "
"You will receive a download link after your application is approved."
"We recommend utilizing the CLI tool from our development kit for a smoother download experience."
"Full instructions can be found in the devkit README available at https://github.com/zenseact/zod."
"Finally load the dataset in the following way\n"
"`datasets.load_dataset('Zenseact/ZOD', config-name, data_dir=data-dir)`")