rshrott commited on
Commit
bcded4e
1 Parent(s): af211ca

Update renovation.py

Browse files
Files changed (1) hide show
  1. renovation.py +55 -55
renovation.py CHANGED
@@ -55,58 +55,58 @@ class RenovationQualityDataset(datasets.GeneratorBasedBuilder):
55
  task_templates=[ImageClassification(image_column="image", label_column="labels")],
56
  )
57
 
58
- def _split_generators(self, dl_manager):
59
- # Download and extract images
60
- image_paths = []
61
- for label, url in _URLS.items():
62
- extract_path = dl_manager.download_and_extract(url)
63
- print(f"Extracted files for label {label} to path: {extract_path}")
64
-
65
- # Get image paths
66
- for root, _, files in os.walk(extract_path):
67
- for file in files:
68
- if file.endswith(".jpeg"): # Assuming all images are .jpeg
69
- image_paths.append((os.path.join(root, file), label))
70
-
71
- print(f"Collected a total of {len(image_paths)} image paths.")
72
-
73
- # Shuffle image paths
74
- random.shuffle(image_paths)
75
-
76
- # 80% for training, 10% for validation, 10% for testing
77
- train_end = int(0.8 * len(image_paths))
78
- val_end = int(0.9 * len(image_paths))
79
-
80
- return [
81
- datasets.SplitGenerator(
82
- name=datasets.Split.TRAIN,
83
- gen_kwargs={
84
- "rows": image_paths[:train_end],
85
- },
86
- ),
87
- datasets.SplitGenerator(
88
- name=datasets.Split.VALIDATION,
89
- gen_kwargs={
90
- "rows": image_paths[train_end:val_end],
91
- },
92
- ),
93
- datasets.SplitGenerator(
94
- name=datasets.Split.TEST,
95
- gen_kwargs={
96
- "rows": image_paths[val_end:],
97
- },
98
- ),
99
- ]
100
-
101
- def _generate_examples(self, rows):
102
- def file_to_image(file_path):
103
- img = Image.open(file_path)
104
- return np.array(img)
105
-
106
- for id_, (image_file_path, label) in enumerate(rows):
107
- image = file_to_image(image_file_path)
108
- yield id_, {
109
- 'image_file_path': image_file_path,
110
- 'image': image,
111
- 'labels': label,
112
- }
 
55
  task_templates=[ImageClassification(image_column="image", label_column="labels")],
56
  )
57
 
58
+ def _split_generators(self, dl_manager):
59
+ # Download and extract images
60
+ image_paths = []
61
+ for label, url in _URLS.items():
62
+ extract_path = dl_manager.download_and_extract(url)
63
+ print(f"Extracted files for label {label} to path: {extract_path}")
64
+
65
+ # Get image paths
66
+ for root, _, files in os.walk(extract_path):
67
+ for file in files:
68
+ if file.endswith(".jpeg"): # Assuming all images are .jpeg
69
+ image_paths.append((os.path.join(root, file), label))
70
+
71
+ print(f"Collected a total of {len(image_paths)} image paths.")
72
+
73
+ # Shuffle image paths
74
+ random.shuffle(image_paths)
75
+
76
+ # 80% for training, 10% for validation, 10% for testing
77
+ train_end = int(0.8 * len(image_paths))
78
+ val_end = int(0.9 * len(image_paths))
79
+
80
+ return [
81
+ datasets.SplitGenerator(
82
+ name=datasets.Split.TRAIN,
83
+ gen_kwargs={
84
+ "rows": image_paths[:train_end],
85
+ },
86
+ ),
87
+ datasets.SplitGenerator(
88
+ name=datasets.Split.VALIDATION,
89
+ gen_kwargs={
90
+ "rows": image_paths[train_end:val_end],
91
+ },
92
+ ),
93
+ datasets.SplitGenerator(
94
+ name=datasets.Split.TEST,
95
+ gen_kwargs={
96
+ "rows": image_paths[val_end:],
97
+ },
98
+ ),
99
+ ]
100
+
101
+ def _generate_examples(self, rows):
102
+ def file_to_image(file_path):
103
+ img = Image.open(file_path)
104
+ return np.array(img)
105
+
106
+ for id_, (image_file_path, label) in enumerate(rows):
107
+ image = file_to_image(image_file_path)
108
+ yield id_, {
109
+ 'image_file_path': image_file_path,
110
+ 'image': image,
111
+ 'labels': label,
112
+ }