Jorgvt commited on
Commit
4f9da14
1 Parent(s): dab9eef

only reading the csv once

Browse files
Files changed (1) hide show
  1. TID2008.py +17 -18
TID2008.py CHANGED
@@ -47,34 +47,34 @@ class TID2008(datasets.GeneratorBasedBuilder):
47
 
48
  def _split_generators(self, dl_manager):
49
  data_path = dl_manager.download("data.zip")
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
  return [
52
  datasets.SplitGenerator(
53
  name=datasets.Split.TRAIN,
54
  gen_kwargs={
55
- "data": dl_manager.download_and_extract(data_path),
 
 
56
  "split": "train",
57
  },
58
  )
59
  ]
60
 
61
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
62
- def _generate_examples(self, data, split):
63
- df = pd.read_csv(os.path.join(data, "image_pairs_mos.csv"), index_col=0)
64
- reference_paths = (
65
- df["Reference"]
66
- .apply(lambda x: os.path.join(data, "reference_images", x))
67
- .to_list()
68
- )
69
- distorted_paths = (
70
- df["Distorted"]
71
- .apply(lambda x: os.path.join(data, "distorted_images", x))
72
- .to_list()
73
- )
74
-
75
- for key, (ref, dist, m) in enumerate(
76
- zip(reference_paths, distorted_paths, df["MOS"])
77
- ):
78
  yield (
79
  key,
80
  {
@@ -83,4 +83,3 @@ class TID2008(datasets.GeneratorBasedBuilder):
83
  "mos": m,
84
  },
85
  )
86
-
 
47
 
48
  def _split_generators(self, dl_manager):
49
  data_path = dl_manager.download("data.zip")
50
+ data_path = dl_manager.download_and_extract(data_path)
51
+ df = pd.read_csv(os.path.join(data_path, "image_pairs_mos.csv"), index_col=0)
52
+ reference_paths = (
53
+ df["Reference"]
54
+ .apply(lambda x: os.path.join(data_path, "reference_images", x))
55
+ .to_list()
56
+ )
57
+ distorted_paths = (
58
+ df["Distorted"]
59
+ .apply(lambda x: os.path.join(data_path, "distorted_images", x))
60
+ .to_list()
61
+ )
62
 
63
  return [
64
  datasets.SplitGenerator(
65
  name=datasets.Split.TRAIN,
66
  gen_kwargs={
67
+ "reference": reference_paths,
68
+ "distorted": distorted_paths,
69
+ "mos": df["MOS"],
70
  "split": "train",
71
  },
72
  )
73
  ]
74
 
75
  # method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
76
+ def _generate_examples(self, reference, distorted, mos, split):
77
+ for key, (ref, dist, m) in enumerate(zip(reference, distorted, mos)):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  yield (
79
  key,
80
  {
 
83
  "mos": m,
84
  },
85
  )