MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / DenseNet

Class DenseNet

monai/networks/nets/densenet.py:152–256  ·  view source on GitHub ↗

Densenet based on: `Densely Connected Convolutional Networks `_. Adapted from PyTorch Hub 2D version: https://pytorch.org/vision/stable/models.html#id16. This network is non-deterministic When `spatial_dims` is 3 and CUDA is enabled. Please check th

Source from the content-addressed store, hash-verified

150
151
152class DenseNet(nn.Module):
153 """
154 Densenet based on: `Densely Connected Convolutional Networks <https://arxiv.org/pdf/1608.06993.pdf>`_.
155 Adapted from PyTorch Hub 2D version: https://pytorch.org/vision/stable/models.html#id16.
156 This network is non-deterministic When `spatial_dims` is 3 and CUDA is enabled. Please check the link below
157 for more details:
158 https://pytorch.org/docs/stable/generated/torch.use_deterministic_algorithms.html#torch.use_deterministic_algorithms
159
160 Args:
161 spatial_dims: number of spatial dimensions of the input image.
162 in_channels: number of the input channel.
163 out_channels: number of the output classes.
164 init_features: number of filters in the first convolution layer.
165 growth_rate: how many filters to add each layer (k in paper).
166 block_config: how many layers in each pooling block.
167 bn_size: multiplicative factor for number of bottle neck layers.
168 (i.e. bn_size * k features in the bottleneck layer)
169 act: activation type and arguments. Defaults to relu.
170 norm: feature normalization type and arguments. Defaults to batch norm.
171 dropout_prob: dropout rate after each dense layer.
172 """
173
174 def __init__(
175 self,
176 spatial_dims: int,
177 in_channels: int,
178 out_channels: int,
179 init_features: int = 64,
180 growth_rate: int = 32,
181 block_config: Sequence[int] = (6, 12, 24, 16),
182 bn_size: int = 4,
183 act: str | tuple = ("relu", {"inplace": True}),
184 norm: str | tuple = "batch",
185 dropout_prob: float = 0.0,
186 ) -> None:
187 super().__init__()
188
189 conv_type: type[nn.Conv1d | nn.Conv2d | nn.Conv3d] = Conv[Conv.CONV, spatial_dims]
190 pool_type: type[nn.MaxPool1d | nn.MaxPool2d | nn.MaxPool3d] = Pool[Pool.MAX, spatial_dims]
191 avg_pool_type: type[nn.AdaptiveAvgPool1d | nn.AdaptiveAvgPool2d | nn.AdaptiveAvgPool3d] = Pool[
192 Pool.ADAPTIVEAVG, spatial_dims
193 ]
194
195 self.features = nn.Sequential(
196 OrderedDict(
197 [
198 ("conv0", conv_type(in_channels, init_features, kernel_size=7, stride=2, padding=3, bias=False)),
199 ("norm0", get_norm_layer(name=norm, spatial_dims=spatial_dims, channels=init_features)),
200 ("relu0", get_act_layer(name=act)),
201 ("pool0", pool_type(kernel_size=3, stride=2, padding=1)),
202 ]
203 )
204 )
205
206 in_channels = init_features
207 for i, num_layers in enumerate(block_config):
208 block = _DenseBlock(
209 spatial_dims=spatial_dims,

Callers 6

test_lr_finderMethod · 0.90
test_shapeMethod · 0.90
test_shapeMethod · 0.90
test_shapeMethod · 0.90

Calls

no outgoing calls

Tested by 4

test_lr_finderMethod · 0.72
test_shapeMethod · 0.72
test_shapeMethod · 0.72
test_shapeMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…