DarthReca
commited on
Commit
•
6034380
1
Parent(s):
6b07df6
:lipstick: Better splitting
Browse files- california_burned_areas.py +7 -47
california_burned_areas.py
CHANGED
@@ -60,19 +60,9 @@ class CaBuArConfig(datasets.BuilderConfig):
|
|
60 |
keyword arguments forwarded to super.
|
61 |
"""
|
62 |
|
63 |
-
def __init__(
|
64 |
-
self,
|
65 |
-
load_prefire: bool,
|
66 |
-
train_folds: List[int],
|
67 |
-
validation_folds: List[int],
|
68 |
-
test_folds: List[int],
|
69 |
-
**kwargs
|
70 |
-
):
|
71 |
super(CaBuArConfig, self).__init__(**kwargs)
|
72 |
self.load_prefire = load_prefire
|
73 |
-
self.train_folds = train_folds
|
74 |
-
self.validation_folds = validation_folds
|
75 |
-
self.test_folds = test_folds
|
76 |
|
77 |
|
78 |
class CaBuAr(datasets.GeneratorBasedBuilder):
|
@@ -86,18 +76,12 @@ class CaBuAr(datasets.GeneratorBasedBuilder):
|
|
86 |
version=VERSION,
|
87 |
description="Post-fire only version of the dataset",
|
88 |
load_prefire=False,
|
89 |
-
train_folds=None,
|
90 |
-
validation_folds=None,
|
91 |
-
test_folds=None,
|
92 |
),
|
93 |
CaBuArConfig(
|
94 |
name="pre-post-fire",
|
95 |
version=VERSION,
|
96 |
description="Pre-fire and post-fire version of the dataset",
|
97 |
load_prefire=True,
|
98 |
-
train_folds=None,
|
99 |
-
validation_folds=None,
|
100 |
-
test_folds=None,
|
101 |
),
|
102 |
]
|
103 |
|
@@ -136,49 +120,25 @@ class CaBuAr(datasets.GeneratorBasedBuilder):
|
|
136 |
|
137 |
def _split_generators(self, dl_manager):
|
138 |
h5_file = dl_manager.download(_URLS)
|
139 |
-
# Raise ValueError if train_folds, validation_folds or test_folds are not set
|
140 |
-
if (
|
141 |
-
self.config.train_folds is None
|
142 |
-
or self.config.validation_folds is None
|
143 |
-
or self.config.test_folds is None
|
144 |
-
):
|
145 |
-
raise ValueError("train_folds, validation_folds and test_folds must be set")
|
146 |
|
147 |
return [
|
148 |
datasets.SplitGenerator(
|
149 |
-
name=
|
150 |
# These kwargs will be passed to _generate_examples
|
151 |
gen_kwargs={
|
152 |
-
"
|
153 |
"load_prefire": self.config.load_prefire,
|
154 |
"filepath": h5_file,
|
155 |
},
|
156 |
-
)
|
157 |
-
|
158 |
-
name=datasets.Split.VALIDATION,
|
159 |
-
# These kwargs will be passed to _generate_examples
|
160 |
-
gen_kwargs={
|
161 |
-
"folds": self.config.validation_folds,
|
162 |
-
"load_prefire": self.config.load_prefire,
|
163 |
-
"filepath": h5_file,
|
164 |
-
},
|
165 |
-
),
|
166 |
-
datasets.SplitGenerator(
|
167 |
-
name=datasets.Split.TEST,
|
168 |
-
# These kwargs will be passed to _generate_examples
|
169 |
-
gen_kwargs={
|
170 |
-
"folds": self.config.test_folds,
|
171 |
-
"load_prefire": self.config.load_prefire,
|
172 |
-
"filepath": h5_file,
|
173 |
-
},
|
174 |
-
),
|
175 |
]
|
176 |
|
177 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
178 |
-
def _generate_examples(self,
|
179 |
with h5py.File(filepath, "r") as f:
|
180 |
for uuid, values in f.items():
|
181 |
-
if values.attrs["fold"]
|
182 |
continue
|
183 |
if load_prefire and "pre_fire" not in values:
|
184 |
continue
|
|
|
60 |
keyword arguments forwarded to super.
|
61 |
"""
|
62 |
|
63 |
+
def __init__(self, load_prefire: bool, **kwargs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
super(CaBuArConfig, self).__init__(**kwargs)
|
65 |
self.load_prefire = load_prefire
|
|
|
|
|
|
|
66 |
|
67 |
|
68 |
class CaBuAr(datasets.GeneratorBasedBuilder):
|
|
|
76 |
version=VERSION,
|
77 |
description="Post-fire only version of the dataset",
|
78 |
load_prefire=False,
|
|
|
|
|
|
|
79 |
),
|
80 |
CaBuArConfig(
|
81 |
name="pre-post-fire",
|
82 |
version=VERSION,
|
83 |
description="Pre-fire and post-fire version of the dataset",
|
84 |
load_prefire=True,
|
|
|
|
|
|
|
85 |
),
|
86 |
]
|
87 |
|
|
|
120 |
|
121 |
def _split_generators(self, dl_manager):
|
122 |
h5_file = dl_manager.download(_URLS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
return [
|
125 |
datasets.SplitGenerator(
|
126 |
+
name=fold,
|
127 |
# These kwargs will be passed to _generate_examples
|
128 |
gen_kwargs={
|
129 |
+
"fold": fold,
|
130 |
"load_prefire": self.config.load_prefire,
|
131 |
"filepath": h5_file,
|
132 |
},
|
133 |
+
)
|
134 |
+
for fold in range(0, 5)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
]
|
136 |
|
137 |
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
138 |
+
def _generate_examples(self, fold: int, load_prefire: bool, filepath):
|
139 |
with h5py.File(filepath, "r") as f:
|
140 |
for uuid, values in f.items():
|
141 |
+
if values.attrs["fold"] != fold:
|
142 |
continue
|
143 |
if load_prefire and "pre_fire" not in values:
|
144 |
continue
|