Spaces:
Sleeping
Sleeping
remove excess data
Browse files- data/brain1_kspace.npy +0 -3
- data/brain2_kspace.npy +0 -3
- data/knee1_kspace.npy +0 -3
- data/knee2_kspace.npy +0 -3
- data/prostate2_kspace.npy +0 -3
- save_kspace_to_disk.py +78 -0
- test.py +19 -0
data/brain1_kspace.npy
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:30951c380dffe40b7c851f9631348f783ff6249d98ab17506a7b8f75f6b7286d
|
3 |
-
size 419430528
|
|
|
|
|
|
|
|
data/brain2_kspace.npy
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:6b1d0cdd6d423aa9b67526803adb9e47263587e3501f379880eb5025aa15336b
|
3 |
-
size 524288128
|
|
|
|
|
|
|
|
data/knee1_kspace.npy
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:4a303497f5a0e3b1f6398455a2e1fa9b6a92e2699e5739b3b3767778e2ceb7f3
|
3 |
-
size 68567168
|
|
|
|
|
|
|
|
data/knee2_kspace.npy
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:f7c0492267645e7f0fbd250f533728e91d5979fc626e388846fc48353bfe1793
|
3 |
-
size 1028505728
|
|
|
|
|
|
|
|
data/prostate2_kspace.npy
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:fc06e928ddd938fefda0e82e295a03b89b14834b32b367bb7e538ffbf79a64ef
|
3 |
-
size 1108377728
|
|
|
|
|
|
|
|
save_kspace_to_disk.py
ADDED
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# hello fellow human, this script is used to save kspace data to disk
|
2 |
+
# You may ask why? Well, as it turns out having h5py read the entire .h5 file
|
3 |
+
# and then just accessing the kspace data as numpy array takes around 50 seconds for a single file
|
4 |
+
# and that's just too slow for me. So I'm going to save the kspace data to disk as numpy arrays
|
5 |
+
|
6 |
+
import h5py
|
7 |
+
import huggingface_hub as hfh
|
8 |
+
import numpy as np
|
9 |
+
# datasets
|
10 |
+
# osbm/fastmri-prostate
|
11 |
+
# osbm/fastmri-brain
|
12 |
+
# osbm/fastmri-knee
|
13 |
+
|
14 |
+
# files in the dataset
|
15 |
+
# prostate
|
16 |
+
# - training_T2_1/file_prostate_AXT2_0002.h5
|
17 |
+
# - training_T2_1/file_prostate_AXT2_0015.h5
|
18 |
+
# brain
|
19 |
+
# - multicoil_train/file_brain_AXFLAIR_200_6002442.h5
|
20 |
+
# - multicoil_train/file_brain_AXFLAIR_200_6002487.h5
|
21 |
+
# knee
|
22 |
+
# - singlecoil_train/file1000015.h5
|
23 |
+
# - multicoil_train/file1000015.h5
|
24 |
+
|
25 |
+
# Download files
|
26 |
+
|
27 |
+
file_paths = {
|
28 |
+
"prostate1": hfh.hf_hub_download(
|
29 |
+
repo_id="osbm/fastmri-prostate",
|
30 |
+
filename="training_T2_1/file_prostate_AXT2_0002.h5",
|
31 |
+
repo_type="dataset",
|
32 |
+
cache_dir="./data"
|
33 |
+
),
|
34 |
+
"prostate2": hfh.hf_hub_download(
|
35 |
+
repo_id="osbm/fastmri-prostate",
|
36 |
+
filename="training_T2_1/file_prostate_AXT2_0015.h5",
|
37 |
+
repo_type="dataset",
|
38 |
+
cache_dir="./data"
|
39 |
+
),
|
40 |
+
"brain1": hfh.hf_hub_download(
|
41 |
+
repo_id="osbm/fastmri-brain",
|
42 |
+
filename="multicoil_train/file_brain_AXFLAIR_200_6002442.h5",
|
43 |
+
repo_type="dataset",
|
44 |
+
cache_dir="./data"
|
45 |
+
),
|
46 |
+
"brain2": hfh.hf_hub_download(
|
47 |
+
repo_id="osbm/fastmri-brain",
|
48 |
+
filename="multicoil_train/file_brain_AXFLAIR_200_6002487.h5",
|
49 |
+
repo_type="dataset",
|
50 |
+
cache_dir="./data"
|
51 |
+
),
|
52 |
+
"knee1": hfh.hf_hub_download(
|
53 |
+
repo_id="osbm/fastmri-knee",
|
54 |
+
filename="singlecoil_train/file1000015.h5",
|
55 |
+
repo_type="dataset",
|
56 |
+
cache_dir="./data"
|
57 |
+
),
|
58 |
+
"knee2": hfh.hf_hub_download(
|
59 |
+
repo_id="osbm/fastmri-knee",
|
60 |
+
filename="multicoil_train/file1000015.h5",
|
61 |
+
repo_type="dataset",
|
62 |
+
cache_dir="./data"
|
63 |
+
)
|
64 |
+
}
|
65 |
+
|
66 |
+
for key, file_path in file_paths.items():
|
67 |
+
print(f"{key}: {file_path}")
|
68 |
+
|
69 |
+
file = h5py.File(file_path, "r")
|
70 |
+
kspace = file["kspace"][()]
|
71 |
+
|
72 |
+
print(kspace.shape)
|
73 |
+
if key.startswith("prostate"):
|
74 |
+
kspace = kspace[0, :, :, :] + kspace[1, :, :, :]
|
75 |
+
|
76 |
+
print(kspace.shape)
|
77 |
+
|
78 |
+
np.save(f"./data/{key}_kspace.npy", kspace)
|
test.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastmri.data.subsample import create_mask_for_mask_type
|
2 |
+
from fastmri.data.transforms import apply_mask, to_tensor, center_crop
|
3 |
+
import numpy as np
|
4 |
+
|
5 |
+
mask_func =create_mask_for_mask_type(
|
6 |
+
mask_type_str="equispaced",
|
7 |
+
center_fractions=[0.37],
|
8 |
+
accelerations=[4]
|
9 |
+
)
|
10 |
+
|
11 |
+
kspace = np.load("data/prostate1_kspace.npy")
|
12 |
+
print(kspace.shape) # (34, 14, 640, 451)
|
13 |
+
kspace = to_tensor(kspace)
|
14 |
+
print(kspace.shape) # torch.Size([34, 14, 640, 451, 2])
|
15 |
+
subsampled_kspace, mask, num_low_frequencies = apply_mask(
|
16 |
+
kspace,
|
17 |
+
mask_func,
|
18 |
+
seed=1
|
19 |
+
)
|