Update renovation.py
Browse files- renovation.py +17 -10
renovation.py
CHANGED
@@ -21,7 +21,7 @@ _CITATION = """\
|
|
21 |
|
22 |
_DESCRIPTION = """\
|
23 |
Renovations is a dataset of images of houses taken in the field using smartphone
|
24 |
-
cameras. It consists of 7 classes: Not Applicable, Very Poor, Poor, Fair, Good,
|
25 |
Data was collected by the your research lab.
|
26 |
"""
|
27 |
|
@@ -82,19 +82,25 @@ class Renovations(datasets.GeneratorBasedBuilder):
|
|
82 |
]
|
83 |
|
84 |
def _generate_examples(self, data_files, split):
|
85 |
-
|
|
|
86 |
for label, path in data_files.items():
|
87 |
-
files =
|
88 |
-
|
89 |
|
|
|
90 |
random.seed(43) # ensure reproducibility
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
|
|
|
|
|
|
97 |
|
|
|
98 |
if split == "train":
|
99 |
data_to_use = train_data
|
100 |
elif split == "test":
|
@@ -102,6 +108,7 @@ class Renovations(datasets.GeneratorBasedBuilder):
|
|
102 |
else: # "val" split
|
103 |
data_to_use = val_data
|
104 |
|
|
|
105 |
for idx, (file, label) in enumerate(data_to_use):
|
106 |
yield idx, {
|
107 |
"image_file_path": file,
|
|
|
21 |
|
22 |
_DESCRIPTION = """\
|
23 |
Renovations is a dataset of images of houses taken in the field using smartphone
|
24 |
+
cameras. It consists of 7 classes: Not Applicable, Very Poor, Poor, Fair, Good, Great and Excellent renovations.
|
25 |
Data was collected by the your research lab.
|
26 |
"""
|
27 |
|
|
|
82 |
]
|
83 |
|
84 |
def _generate_examples(self, data_files, split):
|
85 |
+
# Separate data by class
|
86 |
+
data_by_class = {label: [] for label in _NAMES}
|
87 |
for label, path in data_files.items():
|
88 |
+
files = [os.path.join(path, f) for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]
|
89 |
+
data_by_class[label].extend((file, label) for file in files)
|
90 |
|
91 |
+
# Shuffle and split data for each class
|
92 |
random.seed(43) # ensure reproducibility
|
93 |
+
train_data, test_data, val_data = [], [], []
|
94 |
+
for label, files_and_labels in data_by_class.items():
|
95 |
+
random.shuffle(files_and_labels)
|
96 |
+
num_files = len(files_and_labels)
|
97 |
+
train_end = int(num_files * 0.8)
|
98 |
+
test_end = int(num_files * 0.9)
|
99 |
+
train_data.extend(files_and_labels[:train_end])
|
100 |
+
test_data.extend(files_and_labels[train_end:test_end])
|
101 |
+
val_data.extend(files_and_labels[test_end:])
|
102 |
|
103 |
+
# Select the appropriate split
|
104 |
if split == "train":
|
105 |
data_to_use = train_data
|
106 |
elif split == "test":
|
|
|
108 |
else: # "val" split
|
109 |
data_to_use = val_data
|
110 |
|
111 |
+
# Yield examples
|
112 |
for idx, (file, label) in enumerate(data_to_use):
|
113 |
yield idx, {
|
114 |
"image_file_path": file,
|