| import os |
| import re |
|
|
| import pandas as pd |
| import datasets |
|
|
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| _DESCRIPTION = """""" |
|
|
| _HOMEPAGE = "" |
| _REPO = "" |
|
|
| |
| class IlluminantConfig(datasets.BuilderConfig): |
| """BuilderConfig for IlluminantChanges.""" |
|
|
| def __init__(self, data_url, **kwargs): |
| """BuilderConfig for Imagette. |
| Args: |
| data_url: `string`, url to download the zip file from. |
| matadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs |
| **kwargs: keyword arguments forwarded to super. |
| """ |
| super(IlluminantConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs) |
| self.data_url = data_url |
|
|
| class Databases_IlluminantChanges(datasets.GeneratorBasedBuilder): |
| """""" |
|
|
| VERSION = datasets.Version("1.0.0") |
|
|
| BUILDER_CONFIGS = [ |
| IlluminantConfig( |
| name="MNIST", |
| description="MNIST data", |
| data_url=f"./MNIST.zip", |
| ), |
| IlluminantConfig( |
| name="CIFAR", |
| description="CIFAR data", |
| data_url=f"./CIFAR.zip", |
| ), |
| IlluminantConfig( |
| name="Imagenet", |
| description="Imagenet data", |
| data_url=f"./Imagenet.zip", |
| ), |
| IlluminantConfig( |
| name="TID13", |
| description="TID13 data", |
| data_url=f"./TID13.zip", |
| ), |
| ] |
|
|
| def _info(self): |
| |
| features = datasets.Features( |
| { |
| |
| "reference": datasets.Image(), |
| "distorted": datasets.Image(), |
| |
| } |
| ) |
| return datasets.DatasetInfo( |
| description=_DESCRIPTION, |
| features=features, |
| |
| homepage=_HOMEPAGE, |
| |
| |
| ) |
|
|
| def _split_generators(self, dl_manager): |
|
|
| archive_path = dl_manager.download(self.config.data_url) |
| |
| return [ |
| datasets.SplitGenerator( |
| name=datasets.Split.TRAIN, |
| gen_kwargs={ |
| "images": dl_manager.download_and_extract(archive_path), |
| "split": "train", |
| }, |
| ) |
| ] |
|
|
| def _generate_examples(self, images, split): |
| desat_path = os.path.join(images, self.config.name, "Desat") |
| illum_path = os.path.join(images, self.config.name, "Illum") |
|
|
| illum_paths = [os.path.join(illum_path, p) for p in os.listdir(illum_path)] |
|
|
| |
| img_numbers = [re.findall("im_(\d+)_tono_\d+_sat_\d+.png", p)[0] for p in illum_paths] |
| desat_paths = [os.path.join(desat_path, f"im_orig_desat{n}.png") for n in img_numbers] |
|
|
| |
| for key, (desat, illum) in enumerate(zip(desat_paths, illum_paths)): |
| yield key, { |
| "reference": desat, |
| "distorted": illum, |
| } |