|
a |
|
b/transforms.py |
|
|
1 |
from monai.transforms import ( |
|
|
2 |
Compose, |
|
|
3 |
ToTensord, |
|
|
4 |
RandFlipd, |
|
|
5 |
Spacingd, |
|
|
6 |
RandScaleIntensityd, |
|
|
7 |
RandShiftIntensityd, |
|
|
8 |
NormalizeIntensityd, |
|
|
9 |
AddChanneld, |
|
|
10 |
DivisiblePadd |
|
|
11 |
) |
|
|
12 |
|
|
|
13 |
|
|
|
14 |
#Transforms to be applied on training instances |
|
|
15 |
train_transform = Compose( |
|
|
16 |
[ |
|
|
17 |
AddChanneld(keys=["image", "label"]), |
|
|
18 |
Spacingd(keys=['image', 'label'], pixdim=(1., 1., 1.), mode=("bilinear", "nearest")), |
|
|
19 |
RandFlipd(keys=['image', 'label'], prob=0.5, spatial_axis=0), |
|
|
20 |
RandFlipd(keys=['image', 'label'], prob=0.5, spatial_axis=1), |
|
|
21 |
RandFlipd(keys=['image', 'label'], prob=0.5, spatial_axis=2), |
|
|
22 |
NormalizeIntensityd(keys='image', nonzero=True, channel_wise=True), |
|
|
23 |
RandScaleIntensityd(keys='image', factors=0.1, prob=1.0), |
|
|
24 |
RandShiftIntensityd(keys='image', offsets=0.1, prob=1.0), |
|
|
25 |
DivisiblePadd(k=16, keys=["image", "label"]), |
|
|
26 |
ToTensord(keys=['image', 'label']) |
|
|
27 |
] |
|
|
28 |
) |
|
|
29 |
|
|
|
30 |
#Cuda version of "train_transform" |
|
|
31 |
train_transform_cuda = Compose( |
|
|
32 |
[ |
|
|
33 |
AddChanneld(keys=["image", "label"]), |
|
|
34 |
Spacingd(keys=['image', 'label'], pixdim=(1., 1., 1.), mode=("bilinear", "nearest")), |
|
|
35 |
RandFlipd(keys=['image', 'label'], prob=0.5, spatial_axis=0), |
|
|
36 |
RandFlipd(keys=['image', 'label'], prob=0.5, spatial_axis=1), |
|
|
37 |
RandFlipd(keys=['image', 'label'], prob=0.5, spatial_axis=2), |
|
|
38 |
NormalizeIntensityd(keys='image', nonzero=True, channel_wise=True), |
|
|
39 |
RandScaleIntensityd(keys='image', factors=0.1, prob=1.0), |
|
|
40 |
RandShiftIntensityd(keys='image', offsets=0.1, prob=1.0), |
|
|
41 |
DivisiblePadd(k=16, keys=["image", "label"]), |
|
|
42 |
ToTensord(keys=['image', 'label'], device='cuda') |
|
|
43 |
] |
|
|
44 |
) |
|
|
45 |
|
|
|
46 |
#Transforms to be applied on validation instances |
|
|
47 |
val_transform = Compose( |
|
|
48 |
[ |
|
|
49 |
AddChanneld(keys=["image", "label"]), |
|
|
50 |
NormalizeIntensityd(keys='image', nonzero=True, channel_wise=True), |
|
|
51 |
DivisiblePadd(k=16, keys=["image", "label"]), |
|
|
52 |
ToTensord(keys=['image', 'label']) |
|
|
53 |
] |
|
|
54 |
) |
|
|
55 |
|
|
|
56 |
#Cuda version of "val_transform" |
|
|
57 |
val_transform_cuda = Compose( |
|
|
58 |
[ |
|
|
59 |
AddChanneld(keys=["image", "label"]), |
|
|
60 |
NormalizeIntensityd(keys='image', nonzero=True, channel_wise=True), |
|
|
61 |
DivisiblePadd(k=16, keys=["image", "label"]), |
|
|
62 |
ToTensord(keys=['image', 'label'], device='cuda') |
|
|
63 |
] |
|
|
64 |
) |