| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| """PIRM dataset: An validation and test dataset for the image super resolution task""" |
|
|
|
|
| import datasets |
| from pathlib import Path |
|
|
|
|
| _CITATION = """ |
| @misc{shoeiby2019pirm2018, |
| title={PIRM2018 Challenge on Spectral Image Super-Resolution: Dataset and Study}, |
| author={Mehrdad Shoeiby and Antonio Robles-Kelly and Ran Wei and Radu Timofte}, |
| year={2019}, |
| eprint={1904.00540}, |
| archivePrefix={arXiv}, |
| primaryClass={cs.CV} |
| } |
| """ |
|
|
| _DESCRIPTION = """ |
| The PIRM dataset consists of 200 images, which are divided into two equal sets for validation and testing. |
| These images cover diverse contents, including people, objects, environments, flora, natural scenery, etc. |
| Images vary in size, and are typically ~300K pixels in resolution. |
| |
| This dataset was first used for evaluating the perceptual quality of super-resolution algorithms in The 2018 PIRM |
| challenge on Perceptual Super-resolution, in conjunction with ECCV 2018. |
| """ |
|
|
| _HOMEPAGE = "https://github.com/roimehrez/PIRM2018" |
|
|
| _LICENSE = "cc-by-nc-sa-4.0" |
|
|
| _DL_URL = "https://huggingface.co/datasets/eugenesiow/PIRM/resolve/main/data/" |
|
|
| _DEFAULT_CONFIG = "bicubic_x2" |
|
|
| _DATA_OPTIONS = { |
| "bicubic_x2": { |
| "hr_test": _DL_URL + "PIRM_test_HR.tar.gz", |
| "lr_test": _DL_URL + "PIRM_test_LR_x2.tar.gz", |
| "hr_valid": _DL_URL + "PIRM_valid_HR.tar.gz", |
| "lr_valid": _DL_URL + "PIRM_valid_LR_x2.tar.gz", |
| }, |
| "bicubic_x3": { |
| "hr_test": _DL_URL + "PIRM_test_HR.tar.gz", |
| "lr_test": _DL_URL + "PIRM_test_LR_x3.tar.gz", |
| "hr_valid": _DL_URL + "PIRM_valid_HR.tar.gz", |
| "lr_valid": _DL_URL + "PIRM_valid_LR_x3.tar.gz", |
| }, |
| "bicubic_x4": { |
| "hr_test": _DL_URL + "PIRM_test_HR.tar.gz", |
| "lr_test": _DL_URL + "PIRM_test_LR_x4.tar.gz", |
| "hr_valid": _DL_URL + "PIRM_valid_HR.tar.gz", |
| "lr_valid": _DL_URL + "PIRM_valid_LR_x4.tar.gz", |
| }, |
| "unknown_x4": { |
| "hr_test": _DL_URL + "PIRM_test_HR.tar.gz", |
| "lr_test": _DL_URL + "PIRM_test_LR_unknown_x4.tar.gz", |
| "hr_valid": _DL_URL + "PIRM_valid_HR.tar.gz", |
| "lr_valid": _DL_URL + "PIRM_valid_LR_unknown_x4.tar.gz", |
| } |
| } |
|
|
|
|
| class PirmConfig(datasets.BuilderConfig): |
| """BuilderConfig for PIRM.""" |
|
|
| def __init__( |
| self, |
| name, |
| download_urls, |
| **kwargs, |
| ): |
| if name not in _DATA_OPTIONS: |
| raise ValueError("data must be one of %s" % _DATA_OPTIONS) |
| super(PirmConfig, self).__init__(name=name, version=datasets.Version("1.0.0"), **kwargs) |
| self.download_urls = download_urls |
|
|
|
|
| class Pirm(datasets.GeneratorBasedBuilder): |
| """PIRM dataset for single image super resolution test and validation.""" |
|
|
| BUILDER_CONFIGS = [ |
| PirmConfig( |
| name=key, |
| download_urls=values, |
| ) 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.""" |
| extracted_paths = dl_manager.download_and_extract( |
| self.config.download_urls) |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.VALIDATION, |
| gen_kwargs={ |
| "lr_path": extracted_paths["lr_valid"], |
| "hr_path": str(Path(extracted_paths["hr_valid"]) / 'PIRM_valid_HR') |
| }, |
| ), |
| datasets.SplitGenerator( |
| name=datasets.Split.TEST, |
| gen_kwargs={ |
| "lr_path": extracted_paths["lr_test"], |
| "hr_path": str(Path(extracted_paths["hr_test"]) / 'PIRM_test_HR') |
| }, |
| ) |
| ] |
|
|
| def _generate_examples( |
| self, hr_path, lr_path |
| ): |
| """ Yields examples as (key, example) tuples. """ |
| |
| |
| extensions = {'.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()) |
| } |
|
|