[f1e01c]: / monai / configs / segres20_all_round2.py

Download this file

160 lines (139 with data), 4.1 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
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import numpy as np
import torch
from monai.transforms import (
Compose,
LoadImaged,
RandSpatialCropd,
EnsureTyped,
CastToTyped,
NormalizeIntensityd,
RandFlipd,
CenterSpatialCropd,
ScaleIntensityRanged,
RandAffined,
RandScaleIntensityd,
RandShiftIntensityd,
RandCoarseDropoutd,
Rand2DElasticd,
Lambdad,
Resized,
AddChanneld,
RandGaussianNoised,
RandGridDistortiond,
RepeatChanneld,
Transposed,
OneOf,
EnsureChannelFirstd,
RandLambdad,
Spacingd,
FgBgToIndicesd,
CropForegroundd,
RandCropByPosNegLabeld,
ToDeviced,
SpatialPadd,
)
from default_config import basic_cfg
cfg = basic_cfg
# train
cfg.train = True
cfg.eval = False
cfg.start_eval_epoch = 0 # when use large lr, can set a large num
cfg.run_org_eval = False
cfg.run_tta_val = False
cfg.load_best_weights = False
cfg.amp = False
cfg.val_amp = False
cfg.num_workers = 8
cfg.model_type = "segres20"
# device
cfg.gpu = 0
cfg.device = "cuda:%d" % cfg.gpu
# lr
# warmup_restart, cosine
cfg.lr_mode = "cosine"
cfg.lr = 1e-4
cfg.min_lr = 1e-6
cfg.weight_decay = 1e-6
cfg.epochs = 20
cfg.restart_epoch = 2 # only for warmup_restart
cfg.eval_epochs = 1
cfg.finetune_lb = -1
# dataset
cfg.img_size = (224, 224, 80)
cfg.spacing = (1.5, 1.5, 1.5)
cfg.batch_size = 4
cfg.val_batch_size = 1
cfg.train_cache_rate = 0.0
cfg.val_cache_rate = 0.0
cfg.gpu_cache = False
cfg.val_gpu_cache = False
# val
cfg.roi_size = (224, 224, 80)
cfg.sw_batch_size = 4
# model
# loss
cfg.w_dice = 1.0
cfg.output_dir = "./output/segres20_all_round2"
# transforms
cfg.train_transforms = Compose(
[
LoadImaged(keys=["image", "mask"]),
EnsureChannelFirstd(keys=["image", "mask"]),
# Spacingd(keys=["image", "mask"], pixdim=cfg.spacing, mode=("bilinear", "nearest")),
RandSpatialCropd(
keys=("image", "mask"),
roi_size=cfg.img_size,
random_size=False,
),
Lambdad(keys="image", func=lambda x: x / x.max()),
RandFlipd(keys=("image", "mask"), prob=0.5, spatial_axis=[0]),
RandFlipd(keys=("image", "mask"), prob=0.5, spatial_axis=[1]),
# RandFlipd(keys=("image", "mask"), prob=0.5, spatial_axis=[2]),
RandAffined(
keys=("image", "mask"),
prob=0.5,
rotate_range=np.pi / 12,
translate_range=(cfg.img_size[0]*0.0625, cfg.img_size[1]*0.0625),
scale_range=(0.1, 0.1),
mode="nearest",
padding_mode="reflection",
),
OneOf(
[
RandGridDistortiond(keys=("image", "mask"), prob=0.5, distort_limit=(-0.05, 0.05), mode="nearest", padding_mode="reflection"),
RandCoarseDropoutd(
keys=("image", "mask"),
holes=5,
max_holes=8,
spatial_size=(1, 1, 1),
max_spatial_size=(12, 12, 12),
fill_value=0.0,
prob=0.5,
),
]
),
RandScaleIntensityd(keys="image", factors=(-0.2, 0.2), prob=0.5),
RandShiftIntensityd(keys="image", offsets=(-0.1, 0.1), prob=0.5),
EnsureTyped(keys=("image", "mask"), dtype=torch.float32),
]
)
cfg.val_transforms = Compose(
[
LoadImaged(keys=["image", "mask"]),
EnsureChannelFirstd(keys=["image", "mask"]),
# Spacingd(keys=["image", "mask"], pixdim=cfg.spacing, mode=("bilinear", "nearest")),
Lambdad(keys="image", func=lambda x: x / x.max()),
EnsureTyped(keys=("image", "mask"), dtype=torch.float32),
# ToDeviced(keys=["image", "mask"], device="cuda:0"),
]
)
cfg.org_val_transforms = Compose(
[
LoadImaged(keys="image"),
EnsureChannelFirstd(keys="image"),
# Spacingd(keys="image", pixdim=cfg.spacing, mode="bilinear"),
Lambdad(keys="image", func=lambda x: x / x.max()),
# SpatialPadd(keys="image", spatial_size=cfg.img_size),
EnsureTyped(keys="image", dtype=torch.float32),
]
)