Upload databases_illuminantchanges.py
#5
by
Jorgvt
- opened
- databases_illuminantchanges.py +111 -0
databases_illuminantchanges.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import re
|
| 3 |
+
|
| 4 |
+
import pandas as pd
|
| 5 |
+
import datasets
|
| 6 |
+
|
| 7 |
+
# _CITATION = """\
|
| 8 |
+
# @article{ponomarenko_tid2008_2009,
|
| 9 |
+
# author = {Ponomarenko, Nikolay and Lukin, Vladimir and Zelensky, Alexander and Egiazarian, Karen and Astola, Jaakko and Carli, Marco and Battisti, Federica},
|
| 10 |
+
# title = {{TID2008} -- {A} {Database} for {Evaluation} of {Full}- {Reference} {Visual} {Quality} {Assessment} {Metrics}},
|
| 11 |
+
# year = {2009}
|
| 12 |
+
# }
|
| 13 |
+
# """
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
_DESCRIPTION = """"""
|
| 17 |
+
|
| 18 |
+
_HOMEPAGE = ""
|
| 19 |
+
_REPO = ""
|
| 20 |
+
|
| 21 |
+
# _LICENSE = ""
|
| 22 |
+
class IlluminantConfig(datasets.BuilderConfig):
|
| 23 |
+
"""BuilderConfig for IlluminantChanges."""
|
| 24 |
+
|
| 25 |
+
def __init__(self, data_url, **kwargs):
|
| 26 |
+
"""BuilderConfig for Imagette.
|
| 27 |
+
Args:
|
| 28 |
+
data_url: `string`, url to download the zip file from.
|
| 29 |
+
matadata_urls: dictionary with keys 'train' and 'validation' containing the archive metadata URLs
|
| 30 |
+
**kwargs: keyword arguments forwarded to super.
|
| 31 |
+
"""
|
| 32 |
+
super(IlluminantConfig, self).__init__(version=datasets.Version("1.0.0"), **kwargs)
|
| 33 |
+
self.data_url = data_url
|
| 34 |
+
|
| 35 |
+
class Databases_IlluminantChanges(datasets.GeneratorBasedBuilder):
|
| 36 |
+
""""""
|
| 37 |
+
|
| 38 |
+
VERSION = datasets.Version("1.0.0")
|
| 39 |
+
|
| 40 |
+
BUILDER_CONFIGS = [
|
| 41 |
+
IlluminantConfig(
|
| 42 |
+
name="MNIST",
|
| 43 |
+
description="MNIST data",
|
| 44 |
+
data_url=f"./MNIST.zip",
|
| 45 |
+
),
|
| 46 |
+
IlluminantConfig(
|
| 47 |
+
name="CIFAR",
|
| 48 |
+
description="CIFAR data",
|
| 49 |
+
data_url=f"./CIFAR.zip",
|
| 50 |
+
),
|
| 51 |
+
IlluminantConfig(
|
| 52 |
+
name="Imagenet",
|
| 53 |
+
description="Imagenet data",
|
| 54 |
+
data_url=f"./Imagenet.zip",
|
| 55 |
+
),
|
| 56 |
+
IlluminantConfig(
|
| 57 |
+
name="TID2013",
|
| 58 |
+
description="TID2013 data",
|
| 59 |
+
data_url=f"./TID2013.zip",
|
| 60 |
+
),
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
def _info(self):
|
| 64 |
+
# TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
|
| 65 |
+
features = datasets.Features(
|
| 66 |
+
{
|
| 67 |
+
# "images": datasets.Image(),
|
| 68 |
+
"reference": datasets.Image(),
|
| 69 |
+
"distorted": datasets.Image(),
|
| 70 |
+
# "mos": datasets.Value("float")
|
| 71 |
+
}
|
| 72 |
+
)
|
| 73 |
+
return datasets.DatasetInfo(
|
| 74 |
+
description=_DESCRIPTION,
|
| 75 |
+
features=features,
|
| 76 |
+
# supervised_keys=("reference", "distorted", "mos"),
|
| 77 |
+
homepage=_HOMEPAGE,
|
| 78 |
+
# license=_LICENSE,
|
| 79 |
+
# citation=_CITATION,
|
| 80 |
+
)
|
| 81 |
+
|
| 82 |
+
def _split_generators(self, dl_manager):
|
| 83 |
+
|
| 84 |
+
archive_path = dl_manager.download(self.config.data_url)
|
| 85 |
+
print(f"Data url: {self.config.data_url} | {archive_path}")
|
| 86 |
+
return [
|
| 87 |
+
datasets.SplitGenerator(
|
| 88 |
+
name=datasets.Split.TRAIN,
|
| 89 |
+
gen_kwargs={
|
| 90 |
+
"images": dl_manager.download_and_extract(archive_path),
|
| 91 |
+
"split": "train",
|
| 92 |
+
},
|
| 93 |
+
)
|
| 94 |
+
]
|
| 95 |
+
|
| 96 |
+
def _generate_examples(self, images, split):
|
| 97 |
+
desat_path = os.path.join(images, self.config.name, "Desat")
|
| 98 |
+
illum_path = os.path.join(images, self.config.name, "Illum")
|
| 99 |
+
|
| 100 |
+
illum_paths = [os.path.join(illum_path, p) for p in os.listdir(illum_path)]
|
| 101 |
+
|
| 102 |
+
## Get the correct desat image for each illum image
|
| 103 |
+
img_numbers = [re.findall("\d+", p)[0] for p in illum_paths]
|
| 104 |
+
desat_paths = [os.path.join(desat_path, f"im_orig_desat{n}.png") for n in img_numbers]
|
| 105 |
+
|
| 106 |
+
print(desat_paths[0], illum_paths[0])
|
| 107 |
+
for key, (desat, illum) in enumerate(zip(desat_paths, illum_paths)):
|
| 108 |
+
yield key, {
|
| 109 |
+
"reference": desat,
|
| 110 |
+
"distorted": illum,
|
| 111 |
+
}
|