|
"""TODO: Add a description here.""" |
|
|
|
import csv |
|
import json |
|
import os |
|
import numpy as np |
|
from pathlib import Path |
|
import datasets |
|
|
|
|
|
|
|
|
|
_CITATION = """\ |
|
@InProceedings{huggingface:dataset, |
|
title = {A great new dataset}, |
|
author={huggingface, Inc. |
|
}, |
|
year={2020} |
|
} |
|
""" |
|
|
|
|
|
|
|
_DESCRIPTION = """\ |
|
This new dataset is designed to solve this great NLP task and is crafted with a lot of care. |
|
""" |
|
|
|
|
|
_HOMEPAGE = "" |
|
|
|
|
|
_LICENSE = "" |
|
|
|
|
|
|
|
|
|
_URLS = { |
|
|
|
|
|
"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), |
|
} |
|
|