rshrott commited on
Commit
1ea2b26
·
1 Parent(s): 624bf9e

Update renovation.py

Browse files
Files changed (1) hide show
  1. renovation.py +13 -7
renovation.py CHANGED
@@ -83,20 +83,26 @@ class RenovationQualityDataset(datasets.GeneratorBasedBuilder):
83
 
84
  with open(filepath, "r") as f:
85
  reader = csv.reader(f)
86
- header = next(reader) # Get the header row
87
- image_file_path_index = header.index("image_file_path") # Find the index of "image_file_path" column
88
- label_index = header.index("label") # Find the index of "label" column
89
- for id_, row in enumerate(reader):
 
 
 
 
 
 
90
  if len(row) < 2:
91
  print(f"Row with id {id_} has less than 2 elements: {row}")
92
  else:
93
- image_file_path = row[image_file_path_index]
94
  image = url_to_image(image_file_path)
95
  image_bytes = image.tobytes()
96
- label = row[label_index]
97
  yield id_, {
98
  'image_file_path': image_file_path,
99
  'image': image_bytes,
100
- 'label': label,
101
  }
102
 
 
 
83
 
84
  with open(filepath, "r") as f:
85
  reader = csv.reader(f)
86
+ next(reader) # skip header
87
+ rows = list(reader)
88
+ if split == 'train':
89
+ rows = rows[:int(0.8 * len(rows))]
90
+ elif split == 'validation':
91
+ rows = rows[int(0.8 * len(rows)):int(0.9 * len(rows))]
92
+ else: # test
93
+ rows = rows[int(0.9 * len(rows)):]
94
+
95
+ for id_, row in enumerate(rows):
96
  if len(row) < 2:
97
  print(f"Row with id {id_} has less than 2 elements: {row}")
98
  else:
99
+ image_file_path = str(row[0])
100
  image = url_to_image(image_file_path)
101
  image_bytes = image.tobytes()
 
102
  yield id_, {
103
  'image_file_path': image_file_path,
104
  'image': image_bytes,
105
+ 'label': row[1],
106
  }
107
 
108
+