DarthReca
commited on
Commit
•
7d4633f
1
Parent(s):
611bf7b
:new: Added loader
Browse files
loader.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import List, Tuple
|
2 |
+
|
3 |
+
import h5py
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
|
7 |
+
def loader(
|
8 |
+
hdf5_file: str, folds: List[int]
|
9 |
+
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, List[str]]:
|
10 |
+
post = []
|
11 |
+
pre = []
|
12 |
+
masks = []
|
13 |
+
names = []
|
14 |
+
|
15 |
+
# Read hdf5 file and filter by fold
|
16 |
+
with h5py.File(hdf5_file, "r") as f:
|
17 |
+
for uuid, values in f.items():
|
18 |
+
if values.attrs["fold"] not in folds:
|
19 |
+
continue
|
20 |
+
if "pre_fire" not in values:
|
21 |
+
continue
|
22 |
+
|
23 |
+
post.append(values["post_fire"][...])
|
24 |
+
pre.append(values["pre_fire"][...])
|
25 |
+
masks.append(values["mask"][...])
|
26 |
+
names.append(uuid)
|
27 |
+
|
28 |
+
# Convert to numpy arrays
|
29 |
+
post = np.stack(post, axis=0, dtype=np.int32)
|
30 |
+
pre = np.stack(pre, axis=0, dtype=np.int32)
|
31 |
+
masks = np.stack(masks, axis=0, dtype=np.int32)
|
32 |
+
|
33 |
+
return post, pre, masks, names
|