Args: spatial_dims: number of spatial dimensions of the input image. in_channels: number of the input channel. growth_rate: how many filters to add each layer (k in paper). bn_size: multiplicative factor for number of bottle neck layers.
(
self,
spatial_dims: int,
in_channels: int,
growth_rate: int,
bn_size: int,
dropout_prob: float,
act: str | tuple = ("relu", {"inplace": True}),
norm: str | tuple = "batch",
)
| 44 | class _DenseLayer(nn.Module): |
| 45 | |
| 46 | def __init__( |
| 47 | self, |
| 48 | spatial_dims: int, |
| 49 | in_channels: int, |
| 50 | growth_rate: int, |
| 51 | bn_size: int, |
| 52 | dropout_prob: float, |
| 53 | act: str | tuple = ("relu", {"inplace": True}), |
| 54 | norm: str | tuple = "batch", |
| 55 | ) -> None: |
| 56 | """ |
| 57 | Args: |
| 58 | spatial_dims: number of spatial dimensions of the input image. |
| 59 | in_channels: number of the input channel. |
| 60 | growth_rate: how many filters to add each layer (k in paper). |
| 61 | bn_size: multiplicative factor for number of bottle neck layers. |
| 62 | (i.e. bn_size * k features in the bottleneck layer) |
| 63 | dropout_prob: dropout rate after each dense layer. |
| 64 | act: activation type and arguments. Defaults to relu. |
| 65 | norm: feature normalization type and arguments. Defaults to batch norm. |
| 66 | """ |
| 67 | super().__init__() |
| 68 | |
| 69 | out_channels = bn_size * growth_rate |
| 70 | conv_type: Callable = Conv[Conv.CONV, spatial_dims] |
| 71 | dropout_type: Callable = Dropout[Dropout.DROPOUT, spatial_dims] |
| 72 | |
| 73 | self.layers = nn.Sequential() |
| 74 | |
| 75 | self.layers.add_module("norm1", get_norm_layer(name=norm, spatial_dims=spatial_dims, channels=in_channels)) |
| 76 | self.layers.add_module("relu1", get_act_layer(name=act)) |
| 77 | self.layers.add_module("conv1", conv_type(in_channels, out_channels, kernel_size=1, bias=False)) |
| 78 | |
| 79 | self.layers.add_module("norm2", get_norm_layer(name=norm, spatial_dims=spatial_dims, channels=out_channels)) |
| 80 | self.layers.add_module("relu2", get_act_layer(name=act)) |
| 81 | self.layers.add_module("conv2", conv_type(out_channels, growth_rate, kernel_size=3, padding=1, bias=False)) |
| 82 | |
| 83 | if dropout_prob > 0: |
| 84 | self.layers.add_module("dropout", dropout_type(dropout_prob)) |
| 85 | |
| 86 | def forward(self, x: torch.Tensor) -> torch.Tensor: |
| 87 | new_features = self.layers(x) |
nothing calls this directly
no test coverage detected