File size: 2,683 Bytes
9e2121f
 
 
 
 
d3c41ec
 
 
 
 
 
 
 
9e2121f
 
 
 
 
 
d3c41ec
9e2121f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
617a266
9e2121f
617a266
9e2121f
 
 
 
 
 
fc2a476
 
a10df7a
 
 
 
9e2121f
 
 
 
a10df7a
 
9e2121f
 
 
 
 
 
 
 
 
 
 
 
 
5802ac9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import os

import pandas as pd
import datasets

_CITATION = """\
@article{ponomarenko_tid2008_2009,
author = {Ponomarenko, Nikolay and Lukin, Vladimir and Zelensky, Alexander and Egiazarian, Karen and Astola, Jaakko and Carli, Marco and Battisti, Federica},
title = {{TID2008} -- {A} {Database} for {Evaluation} of {Full}- {Reference} {Visual} {Quality} {Assessment} {Metrics}},
year = {2009}
}
"""


_DESCRIPTION = """\
Image Quality Assessment Dataset consisting of 25 reference images, 17 different distortions and 4 intensities per distortion. 
In total there are 1700 (reference, distortion, MOS) tuples.
"""

_HOMEPAGE = "https://www.ponomarenko.info/tid2008.htm"

# _LICENSE = ""

class TID2008(datasets.GeneratorBasedBuilder):
    """TID2008 Image Quality Dataset"""

    VERSION = datasets.Version("1.0.0")

    def _info(self):
        # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
        features = datasets.Features(
            {
                "reference": datasets.Image(),
                "distorted": datasets.Image(),
                "mos": datasets.Value("float")
            }
        )
        return datasets.DatasetInfo(
            description=_DESCRIPTION,
            features=features,
            # supervised_keys=("reference", "distorted", "mos"),
            homepage=_HOMEPAGE,
            # license=_LICENSE,
            citation=_CITATION,
        )

    def _split_generators(self, dl_manager):
        data_path = dl_manager.download("image_pairs_mos.csv")
        data = pd.read_csv(data_path, index_col=0)
        
        reference_paths = data["Reference"].apply(lambda x: os.path.join("reference_images", x)).to_list()
        distorted_paths = data["Distorted"].apply(lambda x: os.path.join("distorted_images", x)).to_list()

        reference_paths = dl_manager.download(reference_paths)
        distorted_paths = dl_manager.download(distorted_paths)

        return [
            datasets.SplitGenerator(
                name=datasets.Split.TRAIN,
                gen_kwargs={
                    "reference": reference_paths,
                    "distorted": distorted_paths,
                    "mos": data["MOS"],
                    "split": "train",
                },
            )
        ]

    # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
    def _generate_examples(self, reference, distorted, mos, split):
        for key, (ref, dist, m) in enumerate(zip(reference, distorted, mos)):
            yield key, {
                "reference": ref,
                "distorted": dist,
                "mos": m,
            }