Update renovation.py
Browse files- renovation.py +15 -3
renovation.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os
|
2 |
import glob
|
|
|
3 |
|
4 |
import datasets
|
5 |
from datasets.tasks import ImageClassification
|
@@ -51,23 +52,34 @@ class Renovations(datasets.GeneratorBasedBuilder):
|
|
51 |
|
52 |
def _split_generators(self, dl_manager):
|
53 |
data_files = dl_manager.download_and_extract(_URLS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
return [
|
55 |
datasets.SplitGenerator(
|
56 |
name=datasets.Split.TRAIN,
|
57 |
gen_kwargs={
|
58 |
-
"files":
|
59 |
},
|
60 |
),
|
61 |
datasets.SplitGenerator(
|
62 |
name=datasets.Split.VALIDATION,
|
63 |
gen_kwargs={
|
64 |
-
"files":
|
65 |
},
|
66 |
),
|
67 |
datasets.SplitGenerator(
|
68 |
name=datasets.Split.TEST,
|
69 |
gen_kwargs={
|
70 |
-
"files":
|
71 |
},
|
72 |
),
|
73 |
]
|
|
|
1 |
import os
|
2 |
import glob
|
3 |
+
import random
|
4 |
|
5 |
import datasets
|
6 |
from datasets.tasks import ImageClassification
|
|
|
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 |
+
"files": train_files,
|
71 |
},
|
72 |
),
|
73 |
datasets.SplitGenerator(
|
74 |
name=datasets.Split.VALIDATION,
|
75 |
gen_kwargs={
|
76 |
+
"files": val_files,
|
77 |
},
|
78 |
),
|
79 |
datasets.SplitGenerator(
|
80 |
name=datasets.Split.TEST,
|
81 |
gen_kwargs={
|
82 |
+
"files": test_files,
|
83 |
},
|
84 |
),
|
85 |
]
|