rshrott commited on
Commit
2df6c0e
1 Parent(s): bce72ea

Update renovation.py

Browse files
Files changed (1) hide show
  1. renovation.py +16 -16
renovation.py CHANGED
@@ -56,53 +56,52 @@ class Renovations(datasets.GeneratorBasedBuilder):
56
  )
57
 
58
  def _split_generators(self, dl_manager):
59
- data_files = dl_manager.download_and_extract(_URLS)
60
  return [
61
  datasets.SplitGenerator(
62
  name=datasets.Split.TRAIN,
63
  gen_kwargs={
64
- "data_files": data_files,
65
  "split": "train",
66
  },
67
  ),
68
  datasets.SplitGenerator(
69
  name=datasets.Split.VALIDATION,
70
  gen_kwargs={
71
- "data_files": data_files,
72
  "split": "val",
73
  },
74
  ),
75
  datasets.SplitGenerator(
76
  name=datasets.Split.TEST,
77
  gen_kwargs={
78
- "data_files": data_files,
79
  "split": "test",
80
  },
81
  ),
82
  ]
83
 
84
- def _generate_examples(self, data_files, split):
85
- all_files_and_labels = []
86
- for label, zip_path in data_files.items():
87
- with zipfile.ZipFile(zip_path, "r") as zip_ref:
88
- folder_name = os.path.splitext(os.path.basename(zip_path))[0] # Get the folder name without extension
89
- files = [f for f in zip_ref.namelist() if f.startswith(folder_name + "/") and f.endswith(".jpeg")]
90
- for file in files:
91
- file_path = os.path.join(self.config.data_dir, os.path.basename(zip_path)[:-4], file)
92
- all_files_and_labels.append((file_path, label))
93
 
 
 
 
 
 
 
 
 
94
  random.seed(43) # ensure reproducibility
95
  random.shuffle(all_files_and_labels)
96
-
97
  num_files = len(all_files_and_labels)
98
  train_data = all_files_and_labels[:int(num_files*0.9)]
99
  val_test_data = all_files_and_labels[int(num_files*0.9):] # This will be used for both val and test
100
-
101
  if split == "train":
102
  data_to_use = train_data
103
  else: # "val" or "test" split
104
  data_to_use = val_test_data
105
-
106
  for idx, (file, label) in enumerate(data_to_use):
107
  yield idx, {
108
  "image_file_path": file,
@@ -111,3 +110,4 @@ class Renovations(datasets.GeneratorBasedBuilder):
111
  }
112
 
113
 
 
 
56
  )
57
 
58
  def _split_generators(self, dl_manager):
59
+ data_dir = dl_manager.download_and_extract(_URLS)
60
  return [
61
  datasets.SplitGenerator(
62
  name=datasets.Split.TRAIN,
63
  gen_kwargs={
64
+ "data_dir": data_dir,
65
  "split": "train",
66
  },
67
  ),
68
  datasets.SplitGenerator(
69
  name=datasets.Split.VALIDATION,
70
  gen_kwargs={
71
+ "data_dir": data_dir,
72
  "split": "val",
73
  },
74
  ),
75
  datasets.SplitGenerator(
76
  name=datasets.Split.TEST,
77
  gen_kwargs={
78
+ "data_dir": data_dir,
79
  "split": "test",
80
  },
81
  ),
82
  ]
83
 
 
 
 
 
 
 
 
 
 
84
 
85
+ def _generate_examples(self, data_dir, split):
86
+ all_files_and_labels = []
87
+ for label in _NAMES:
88
+ folder_path = os.path.join(data_dir, label)
89
+ files = glob.glob(os.path.join(folder_path, "*.jpeg"))
90
+ for file in files:
91
+ all_files_and_labels.append((file, label))
92
+
93
  random.seed(43) # ensure reproducibility
94
  random.shuffle(all_files_and_labels)
95
+
96
  num_files = len(all_files_and_labels)
97
  train_data = all_files_and_labels[:int(num_files*0.9)]
98
  val_test_data = all_files_and_labels[int(num_files*0.9):] # This will be used for both val and test
99
+
100
  if split == "train":
101
  data_to_use = train_data
102
  else: # "val" or "test" split
103
  data_to_use = val_test_data
104
+
105
  for idx, (file, label) in enumerate(data_to_use):
106
  yield idx, {
107
  "image_file_path": file,
 
110
  }
111
 
112
 
113
+