"""TODO: Add a description here.""" import csv import json import os import numpy as np from pathlib import Path import datasets # TODO: Add BibTeX citation # Find for instance the citation on arxiv or on the dataset repo/website _CITATION = """\ @InProceedings{huggingface:dataset, title = {A great new dataset}, author={huggingface, Inc. }, year={2020} } """ # TODO: Add description of the dataset here # You can copy an official description _DESCRIPTION = """\ This new dataset is designed to solve this great NLP task and is crafted with a lot of care. """ # TODO: Add a link to an official homepage for the dataset here _HOMEPAGE = "" # TODO: Add the licence for the dataset here if you can find it _LICENSE = "" # TODO: Add link to the official dataset URLs here # The HuggingFace Datasets library doesn't host the datasets but only points to the original files. # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method) _URLS = { # "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip", # "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip", "small_50": { "train": ( "datasets/jhtdb/small_50/metadata_train.csv", "datasets/jhtdb/small_50/train.zip", ), "val": ( "datasets/jhtdb/small_50/metadata_val.csv", "datasets/jhtdb/small_50/val.zip", ), "test": ( "datasets/jhtdb/small_50/metadata_test.csv", "datasets/jhtdb/small_50/test.zip", ), } } class JHTDB(datasets.GeneratorBasedBuilder): """TODO: Short description of my dataset.""" VERSION = datasets.Version("1.1.0") BUILDER_CONFIGS = [ datasets.BuilderConfig(name="small_50", version=VERSION, description=""), ] DEFAULT_CONFIG_NAME = "small_50" def _info(self): if self.config.name.startswith("small"): features = datasets.Features( { "lrs": datasets.Sequence( datasets.Array4D(shape=(3, 4, 4, 4), dtype="float32"), ), "hr": datasets.Array4D(shape=(3, 16, 16, 16), dtype="float32"), } ) elif self.config.name.startswith("large"): features = datasets.Features( { "lrs": datasets.Sequence( datasets.Array4D(shape=(3, 16, 16, 16), dtype="float32"), ), "hr": datasets.Array4D(shape=(3, 64, 64, 64), dtype="float32"), } ) return datasets.DatasetInfo( description=_DESCRIPTION, features=features, homepage=_HOMEPAGE, license=_LICENSE, citation=_CITATION, ) def _split_generators(self, dl_manager): urls = _URLS[self.config.name] data_dir = dl_manager.download_and_extract(urls) named_splits = { "train": datasets.Split.TRAIN, "val": datasets.Split.VALIDATION, "test": datasets.Split.TEST, } return [ datasets.SplitGenerator( name=named_splits[split], gen_kwargs={ "metadata_path": Path(metadata_path), "data_path": Path(data_path), }, ) for split, (metadata_path, data_path) in data_dir.items() ] def _generate_examples(self, metadata_path: Path, data_path: Path): with open(metadata_path) as f: reader = csv.DictReader(f) for key, data in enumerate(reader): yield key, { "lrs": [ np.load(data_path / Path(p).name) for p in json.loads(data["lr_paths"]) ], "hr": np.load(data_path / Path(data["hr_path"]).name), }