|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Set5 dataset: An evaluation dataset for the image super resolution task""" |
|
|
|
|
|
import datasets |
|
from pathlib import Path |
|
|
|
|
|
_CITATION = """ |
|
@article{bevilacqua2012low, |
|
title={Low-complexity single-image super-resolution based on nonnegative neighbor embedding}, |
|
author={Bevilacqua, Marco and Roumy, Aline and Guillemot, Christine and Alberi-Morel, Marie Line}, |
|
year={2012}, |
|
publisher={BMVA press} |
|
} |
|
""" |
|
|
|
_DESCRIPTION = """ |
|
Set5 is a evaluation dataset with 5 RGB images for the image super resolution task. |
|
""" |
|
|
|
_HOMEPAGE = "http://people.rennes.inria.fr/Aline.Roumy/results/SR_BMVC12.html" |
|
|
|
_LICENSE = "UNK" |
|
|
|
_DL_URL = "https://huggingface.co/datasets/eugenesiow/Set5/resolve/main/data/" |
|
|
|
_DEFAULT_CONFIG = "bicubic_x2" |
|
|
|
_DATA_OPTIONS = { |
|
"bicubic_x2": { |
|
"hr": _DL_URL + "Set5_HR.tar.gz", |
|
"lr": _DL_URL + "Set5_LR_x2.tar.gz", |
|
}, |
|
"bicubic_x3": { |
|
"hr": _DL_URL + "Set5_HR.tar.gz", |
|
"lr": _DL_URL + "Set5_LR_x3.tar.gz", |
|
}, |
|
"bicubic_x4": { |
|
"hr": _DL_URL + "Set5_HR.tar.gz", |
|
"lr": _DL_URL + "Set5_LR_x4.tar.gz", |
|
} |
|
} |
|
|
|
|
|
class Set5Config(datasets.BuilderConfig): |
|
"""BuilderConfig for Set5.""" |
|
|
|
def __init__( |
|
self, |
|
name, |
|
hr_url, |
|
lr_url, |
|
**kwargs, |
|
): |
|
if name not in _DATA_OPTIONS: |
|
raise ValueError("data must be one of %s" % _DATA_OPTIONS) |
|
super(Set5Config, self).__init__(name=name, version=datasets.Version("1.0.0"), **kwargs) |
|
self.hr_url = hr_url |
|
self.lr_url = lr_url |
|
|
|
|
|
class Set5(datasets.GeneratorBasedBuilder): |
|
"""Set5 dataset for single image super resolution evaluation.""" |
|
|
|
BUILDER_CONFIGS = [ |
|
Set5Config( |
|
name=key, |
|
hr_url=values['hr'], |
|
lr_url=values['lr'] |
|
) for key, values in _DATA_OPTIONS.items() |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = _DEFAULT_CONFIG |
|
|
|
def _info(self): |
|
features = datasets.Features( |
|
{ |
|
"hr": datasets.Value("string"), |
|
"lr": datasets.Value("string"), |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
features=features, |
|
supervised_keys=None, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
"""Returns SplitGenerators.""" |
|
hr_data_dir = dl_manager.download_and_extract(self.config.hr_url) |
|
lr_data_dir = dl_manager.download_and_extract(self.config.lr_url) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.VALIDATION, |
|
|
|
gen_kwargs={ |
|
"lr_path": lr_data_dir, |
|
"hr_path": str(Path(hr_data_dir) / 'Set5_HR') |
|
}, |
|
) |
|
] |
|
|
|
def _generate_examples( |
|
self, hr_path, lr_path |
|
): |
|
""" Yields examples as (key, example) tuples. """ |
|
|
|
|
|
extensions = {'.jpg', '.jpeg', '.png'} |
|
for file_path in sorted(Path(lr_path).glob("**/*")): |
|
if file_path.suffix in extensions: |
|
file_path_str = str(file_path.as_posix()) |
|
yield file_path_str, { |
|
'lr': file_path_str, |
|
'hr': str((Path(hr_path) / file_path.name).as_posix()) |
|
} |
|
|