# # This file is part of the SMVB distribution (https://huggingface.co/datasets/ABC-iRobotics/SMVB). # Copyright (c) 2023 ABC-iRobotics. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 3. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # """SMVB dataset""" import sys import pathlib if sys.version_info < (3, 9): from typing import Sequence, Generator, Tuple else: from collections.abc import Sequence, Generator Tuple = tuple from typing import Optional, IO import datasets import itertools # ---- Constants ---- _CITATION = """\ @INPROCEEDINGS{karoly2024synthetic, author={Károly, Artúr I. and Nádas, Imre and Galambos, Péter}, booktitle={2024 IEEE 22nd World Symposium on Applied Machine Intelligence and Informatics (SAMI)}, title={Synthetic Multimodal Video Benchmark (SMVB): Utilizing Blender for rich dataset generation}, year={2024}, volume={}, number={}, pages={}, doi={}} """ _DESCRIPTION = """\ Amultimodal video benchmark for evaluating models in multi-task learning scenarios. """ _HOMEPAGE = "https://huggingface.co/ABC-iRobotics/SMVB" _LICENSE = "GNU General Public License v3.0" _BASE_URL = "https://huggingface.co/datasets/ABC-iRobotics/SMVB/resolve/main/data" _VERSION = '1.0.0' # ---- SMVB dataset Configs ---- class SMVBDatasetConfig(datasets.BuilderConfig): """BuilderConfig for SMVB dataset.""" def __init__(self, name: str, data_urls: Sequence[str], version: Optional[str] = None, **kwargs): super(SMVBDatasetConfig, self).__init__(version=datasets.Version(version), name=name, **kwargs) self._data_urls = data_urls @property def features(self): return datasets.Features( { "image": datasets.Image(), "mask": datasets.Image(), "depth": datasets.Sequence(datasets.Value("float32")), "flow": datasets.Sequence(datasets.Value("float32")), "normal": datasets.Sequence(datasets.Value("float32")) } ) @property def keys(self): return ("image", "mask", "depth", "flow", "normal") # ---- SMVB dataset Loader ---- class SMVBDataset(datasets.GeneratorBasedBuilder): """SMVB dataset.""" BUILDER_CONFIG_CLASS = SMVBDatasetConfig BUILDER_CONFIGS = [ SMVBDatasetConfig( name = "all", description = "Photorealistic synthetic images", data_urls = [_BASE_URL], version = _VERSION ), ] DEFAULT_WRITER_BATCH_SIZE = 10 def _info(self): return datasets.DatasetInfo( description=_DESCRIPTION, features=self.config.features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, version=self.config.version, ) def _split_generators(self, dl_manager): local_data_paths = dl_manager.download(self.config._data_urls) archives = itertools.chain.from_iterable([pathlib.Path(path).rglob('*.tar.gz') for path in local_data_paths]) local_data_gen = itertools.chain.from_iterable([dl_manager.iter_archive(path) for path in archives]) return [ datasets.SplitGenerator( name=datasets.Split.TRAIN, gen_kwargs={ "data": local_data_gen } ) ] def _generate_examples( self, data: Generator[Tuple[str,IO], None, None] ): file_infos = [] keys = self.config.keys for i, info in enumerate(data): if file_infos and i%len(keys) == 0: yield (i//len(keys))-1, {k:{'path':d[0],'bytes':d[1].read()} for k,d in zip(keys,file_infos)} file_infos = [] file_infos.append(info)