rshrott commited on
Commit
5cd88e4
1 Parent(s): a2eea17

Update renovation.py

Browse files
Files changed (1) hide show
  1. renovation.py +24 -34
renovation.py CHANGED
@@ -52,56 +52,46 @@ class Renovations(datasets.GeneratorBasedBuilder):
52
 
53
  def _split_generators(self, dl_manager):
54
  data_files = dl_manager.download_and_extract(_URLS)
55
- files = glob.glob(data_files["cheap"] + '/*.jpeg', recursive=True) + \
56
- glob.glob(data_files["average"] + '/*.jpeg', recursive=True) + \
57
- glob.glob(data_files["expensive"] + '/*.jpeg', recursive=True)
58
-
59
- # Shuffle files
60
- random.shuffle(files)
61
- num_files = len(files)
62
- train_files = files[:int(num_files*0.7)]
63
- val_files = files[int(num_files*0.7):int(num_files*0.85)]
64
- test_files = files[int(num_files*0.85):]
65
-
66
  return [
67
  datasets.SplitGenerator(
68
  name=datasets.Split.TRAIN,
69
  gen_kwargs={
70
- "files": train_files,
 
71
  },
72
  ),
73
  datasets.SplitGenerator(
74
  name=datasets.Split.VALIDATION,
75
  gen_kwargs={
76
- "files": val_files,
 
77
  },
78
  ),
79
  datasets.SplitGenerator(
80
  name=datasets.Split.TEST,
81
  gen_kwargs={
82
- "files": test_files,
 
83
  },
84
  ),
85
  ]
86
 
87
- def _generate_examples(self, files):
88
- print(f"Processing {len(files)} files:")
89
- for i, path in enumerate(files):
90
- print(f"Processing file {i}: {path}")
91
- dirname = os.path.dirname(path)
92
- print(f"Dirname: {dirname}")
93
- parent_dirname = os.path.dirname(dirname)
94
- print(f"Parent Dirname: {parent_dirname}")
95
- grandparent_dirname = os.path.dirname(parent_dirname)
96
- print(f"Grandparent Dirname: {grandparent_dirname}")
97
- great_grandparent_dirname = os.path.dirname(grandparent_dirname)
98
- print(f"Great Grandparent Dirname: {great_grandparent_dirname}")
99
 
100
- label = os.path.basename(great_grandparent_dirname).lower()
101
- print(f"Label: {label}")
102
- yield i, {
103
- "image_file_path": path,
104
- "image": path,
105
- "labels": label,
106
- }
107
-
 
52
 
53
  def _split_generators(self, dl_manager):
54
  data_files = dl_manager.download_and_extract(_URLS)
 
 
 
 
 
 
 
 
 
 
 
55
  return [
56
  datasets.SplitGenerator(
57
  name=datasets.Split.TRAIN,
58
  gen_kwargs={
59
+ "data_files": data_files,
60
+ "split": "train",
61
  },
62
  ),
63
  datasets.SplitGenerator(
64
  name=datasets.Split.VALIDATION,
65
  gen_kwargs={
66
+ "data_files": data_files,
67
+ "split": "val",
68
  },
69
  ),
70
  datasets.SplitGenerator(
71
  name=datasets.Split.TEST,
72
  gen_kwargs={
73
+ "data_files": data_files,
74
+ "split": "test",
75
  },
76
  ),
77
  ]
78
 
79
+ def _generate_examples(self, data_files, split):
80
+ for label, path in data_files.items():
81
+ files = glob.glob(path + '/*.jpeg', recursive=True)
82
+ random.shuffle(files)
83
+ num_files = len(files)
84
+ if split == "train":
85
+ files = files[:int(num_files*0.7)]
86
+ elif split == "val":
87
+ files = files[int(num_files*0.7):int(num_files*0.85)]
88
+ else:
89
+ files = files[int(num_files*0.85):]
 
90
 
91
+ for i, file in enumerate(files):
92
+ yield i, {
93
+ "image_file_path": file,
94
+ "image": file,
95
+ "labels": label,
96
+ }
97
+