Update renovation.py
Browse files- 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 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
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[
|
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':
|
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 |
+
|