|
a |
|
b/notebooks/train_expansion.py |
|
|
1 |
# %% |
|
|
2 |
import json |
|
|
3 |
import os |
|
|
4 |
import random |
|
|
5 |
|
|
|
6 |
# enable lib loading even if not installed as a pip package or in PYTHONPATH |
|
|
7 |
# also convenient for relative paths in example config files |
|
|
8 |
from pathlib import Path |
|
|
9 |
|
|
|
10 |
os.chdir(Path(__file__).resolve().parent.parent) |
|
|
11 |
|
|
|
12 |
from adpkd_segmentation.data.data_utils import ( # noqa |
|
|
13 |
get_labeled, |
|
|
14 |
make_dcmdicts, |
|
|
15 |
) |
|
|
16 |
from adpkd_segmentation.data.link_data import makelinks # noqa |
|
|
17 |
|
|
|
18 |
# %% |
|
|
19 |
makelinks() |
|
|
20 |
# %% |
|
|
21 |
dcm_paths = sorted(get_labeled()) |
|
|
22 |
dcm2attribs, patient2dcm = make_dcmdicts(tuple(dcm_paths)) |
|
|
23 |
all_patient_IDS = list(patient2dcm.keys()) |
|
|
24 |
|
|
|
25 |
|
|
|
26 |
# %% |
|
|
27 |
with open("./stratification/strat_split_2020_09_24.json", "r") as f: |
|
|
28 |
full_split = json.load(f) |
|
|
29 |
|
|
|
30 |
# %% |
|
|
31 |
new_train = [ |
|
|
32 |
patient_id |
|
|
33 |
for patient_id in all_patient_IDS |
|
|
34 |
if patient_id not in full_split["val"] |
|
|
35 |
and patient_id not in full_split["test"] |
|
|
36 |
] |
|
|
37 |
|
|
|
38 |
# %% |
|
|
39 |
random.seed(42) |
|
|
40 |
random.shuffle(new_train) |
|
|
41 |
|
|
|
42 |
# %% |
|
|
43 |
new = {} |
|
|
44 |
new["val"] = full_split["val"] |
|
|
45 |
new["test"] = full_split["test"] |
|
|
46 |
new["train"] = new_train |
|
|
47 |
# %% |
|
|
48 |
with open("./stratification/strat_split_2020_09_28_extended.json", "w") as f: |
|
|
49 |
json.dump(new, f, indent=4) |
|
|
50 |
|
|
|
51 |
# %% |