bosch-small-traffic-lights-dataset / bosch-small-traffic-lights-dataset.py
Santiago Hincapie-Potes
fix: image relative path
b333b72
# Copyright 2020 The HuggingFace Datasets Authors and Santiago Hincapie-Potes and
# Heidelberg Collaboratory for Image Processing group.
#
# 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.
"""Bosch Small Traffic Lights Dataset"""
import os
import yaml
import datasets
_CITATION = """\
@inproceedings{BehrendtNovak2017ICRA,
title={A Deep Learning Approach to Traffic Lights: Detection, Tracking, and Classification},
author={Behrendt, Karsten and Novak, Libor},
booktitle={Robotics and Automation (ICRA), 2017 IEEE International Conference on},
organization={IEEE}
}
"""
_DESCRIPTION = """\
This dataset contains 13427 camera images at a resolution of 1280x720 pixels and contains about
24000 annotated traffic lights. The annotations include bounding boxes of traffic lights as well
as the current state (active light) of each traffic light. The camera images are provided as raw
12bit HDR images taken with a red-clear-clear-blue filter and as reconstructed 8-bit RGB color
images. The RGB images are provided for debugging and can also be used for training. However, the
RGB conversion process has some drawbacks. Some of the converted images may contain artifacts and
the color distribution may seem unusual.
"""
_HOMEPAGE = "https://hci.iwr.uni-heidelberg.de/content/bosch-small-traffic-lights-dataset"
_LICENSE = "non-commercial use only"
_URL = {
"train": "train.tar.gz",
"test": "test.tar.gz",
}
class BoschSmallTrafficLights(datasets.GeneratorBasedBuilder):
"""Bosch Small Traffic Lights Dataset, an accurate dataset for vision-based traffic light detection."""
VERSION = datasets.Version("1.1.0")
def _info(self):
features = datasets.Features({
"img": datasets.Image(),
"boxes": datasets.features.Sequence({
"label": datasets.Value("string"),
"occluded": datasets.Value("bool"),
"x_max": datasets.Value("float"),
"x_min": datasets.Value("float"),
"y_max": datasets.Value("float"),
"y_min": datasets.Value("float"),
})
})
return datasets.DatasetInfo(
description=_DESCRIPTION,
features=features,
homepage=_HOMEPAGE,
license=_LICENSE,
citation=_CITATION,
)
def _split_generators(self, dl_manager):
urls = _URL
data_dir = dl_manager.download_and_extract(urls)
print(data_dir)
return [
datasets.SplitGenerator(
name=datasets.Split.TRAIN,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"root_dir": data_dir["train"],
"filepath": "train.yaml",
},
),
datasets.SplitGenerator(
name=datasets.Split.TEST,
# These kwargs will be passed to _generate_examples
gen_kwargs={
"root_dir": data_dir["test"],
"filepath": "test.yaml",
},
),
]
def _generate_examples(self, root_dir, filepath):
filepath = os.path.join(root_dir, filepath)
with open(filepath, encoding="utf-8") as f:
data = yaml.load(f, Loader=yaml.FullLoader)
for key, row in enumerate(data):
yield key, {
"img": os.path.join(root_dir, row["path"]),
"boxes": row["boxes"]
}