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