Update renovation.py
Browse files- 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 |
-
"
|
|
|
71 |
},
|
72 |
),
|
73 |
datasets.SplitGenerator(
|
74 |
name=datasets.Split.VALIDATION,
|
75 |
gen_kwargs={
|
76 |
-
"
|
|
|
77 |
},
|
78 |
),
|
79 |
datasets.SplitGenerator(
|
80 |
name=datasets.Split.TEST,
|
81 |
gen_kwargs={
|
82 |
-
"
|
|
|
83 |
},
|
84 |
),
|
85 |
]
|
86 |
|
87 |
-
def _generate_examples(self,
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
print(f"Great Grandparent Dirname: {great_grandparent_dirname}")
|
99 |
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
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 |
+
|
|