read csv only once
Browse files- TID2013.py +17 -17
TID2013.py
CHANGED
@@ -59,34 +59,34 @@ class TID2013(datasets.GeneratorBasedBuilder):
|
|
59 |
|
60 |
def _split_generators(self, dl_manager):
|
61 |
data_path = dl_manager.download("data.zip")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
63 |
return [
|
64 |
datasets.SplitGenerator(
|
65 |
name=datasets.Split.TRAIN,
|
66 |
gen_kwargs={
|
67 |
-
"
|
|
|
|
|
68 |
"split": "train",
|
69 |
},
|
70 |
)
|
71 |
]
|
72 |
|
73 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
74 |
-
def _generate_examples(self,
|
75 |
-
|
76 |
-
reference_paths = (
|
77 |
-
df["Reference"]
|
78 |
-
.apply(lambda x: os.path.join(data, "reference_images", x))
|
79 |
-
.to_list()
|
80 |
-
)
|
81 |
-
distorted_paths = (
|
82 |
-
df["Distorted"]
|
83 |
-
.apply(lambda x: os.path.join(data, "distorted_images", x))
|
84 |
-
.to_list()
|
85 |
-
)
|
86 |
-
|
87 |
-
for key, (ref, dist, m) in enumerate(
|
88 |
-
zip(reference_paths, distorted_paths, df["MOS"])
|
89 |
-
):
|
90 |
yield (
|
91 |
key,
|
92 |
{
|
|
|
59 |
|
60 |
def _split_generators(self, dl_manager):
|
61 |
data_path = dl_manager.download("data.zip")
|
62 |
+
data_path = dl_manager.download_and_extract(data_path)
|
63 |
+
df = pd.read_csv(os.path.join(data_path, "image_pairs_mos.csv"), index_col=0)
|
64 |
+
reference_paths = (
|
65 |
+
df["Reference"]
|
66 |
+
.apply(lambda x: os.path.join(data_path, "reference_images", x))
|
67 |
+
.to_list()
|
68 |
+
)
|
69 |
+
distorted_paths = (
|
70 |
+
df["Distorted"]
|
71 |
+
.apply(lambda x: os.path.join(data_path, "distorted_images", x))
|
72 |
+
.to_list()
|
73 |
+
)
|
74 |
|
75 |
return [
|
76 |
datasets.SplitGenerator(
|
77 |
name=datasets.Split.TRAIN,
|
78 |
gen_kwargs={
|
79 |
+
"reference": reference_paths,
|
80 |
+
"distorted": distorted_paths,
|
81 |
+
"mos": df["MOS"],
|
82 |
"split": "train",
|
83 |
},
|
84 |
)
|
85 |
]
|
86 |
|
87 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
88 |
+
def _generate_examples(self, reference, distorted, mos, split):
|
89 |
+
for key, (ref, dist, m) in enumerate(zip(reference, distorted, mos)):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
yield (
|
91 |
key,
|
92 |
{
|