(
self,
spatial_dims: int = 3,
init_filters: int = 32,
in_channels: int = 1,
act: tuple | str = "relu",
norm: tuple | str = "batch",
blocks_down: tuple = (1, 2, 2, 4),
head_module: nn.Module | None = None,
anisotropic_scales: tuple | None = None,
)
| 142 | """ |
| 143 | |
| 144 | def __init__( |
| 145 | self, |
| 146 | spatial_dims: int = 3, |
| 147 | init_filters: int = 32, |
| 148 | in_channels: int = 1, |
| 149 | act: tuple | str = "relu", |
| 150 | norm: tuple | str = "batch", |
| 151 | blocks_down: tuple = (1, 2, 2, 4), |
| 152 | head_module: nn.Module | None = None, |
| 153 | anisotropic_scales: tuple | None = None, |
| 154 | ): |
| 155 | super().__init__() |
| 156 | |
| 157 | if spatial_dims not in (1, 2, 3): |
| 158 | raise ValueError("`spatial_dims` can only be 1, 2 or 3.") |
| 159 | |
| 160 | # ensure normalization has affine trainable parameters (if not specified) |
| 161 | norm = split_args(norm) |
| 162 | if has_option(Norm[norm[0], spatial_dims], "affine"): |
| 163 | norm[1].setdefault("affine", True) # type: ignore |
| 164 | |
| 165 | # ensure activation is inplace (if not specified) |
| 166 | act = split_args(act) |
| 167 | if has_option(Act[act[0]], "inplace"): |
| 168 | act[1].setdefault("inplace", True) # type: ignore |
| 169 | |
| 170 | filters = init_filters # base number of features |
| 171 | |
| 172 | kernel_size, padding, _ = aniso_kernel(anisotropic_scales[0]) if anisotropic_scales else (3, 1, 1) |
| 173 | self.conv_init = Conv[Conv.CONV, spatial_dims]( |
| 174 | in_channels=in_channels, |
| 175 | out_channels=filters, |
| 176 | kernel_size=kernel_size, |
| 177 | padding=padding, |
| 178 | stride=1, |
| 179 | bias=False, |
| 180 | ) |
| 181 | self.layers = nn.ModuleList() |
| 182 | |
| 183 | for i in range(len(blocks_down)): |
| 184 | level = nn.ModuleDict() |
| 185 | |
| 186 | kernel_size, padding, stride = aniso_kernel(anisotropic_scales[i]) if anisotropic_scales else (3, 1, 2) |
| 187 | blocks = [ |
| 188 | SegResBlock(spatial_dims=spatial_dims, in_channels=filters, kernel_size=kernel_size, norm=norm, act=act) |
| 189 | for _ in range(blocks_down[i]) |
| 190 | ] |
| 191 | level["blocks"] = nn.Sequential(*blocks) |
| 192 | |
| 193 | if i < len(blocks_down) - 1: |
| 194 | level["downsample"] = Conv[Conv.CONV, spatial_dims]( |
| 195 | in_channels=filters, |
| 196 | out_channels=2 * filters, |
| 197 | bias=False, |
| 198 | kernel_size=kernel_size, |
| 199 | stride=stride, |
| 200 | padding=padding, |
| 201 | ) |
nothing calls this directly
no test coverage detected