DenseNet feature-extracting backbone (no classification head).
Implements the densely-connected topology from Huang et al.,
"Densely Connected Convolutional Networks", CVPR 2017: a Conv-BN-
ReLU-MaxPool stem followed by four _DenseBlock stages
interleaved with three _Transition blocks that halve both
the channel and spatial dimensions. Inside each dense block every
layer receives the concatenated feature maps of all preceding
layers in the block. A final BatchNorm + ReLU + global average
pool produces a fixed-size feature regardless of input resolution.
Parameters
configDenseNetConfigdensenet_121, densenet_169, …) for the
paper-cited variants.Attributes
configDenseNetConfigfeatures_Featuresconv0, norm0,
relu0, pool0), the four dense blocks
(denseblock1 … denseblock4), the three transitions
(transition1 … transition3), and the final BatchNorm
(norm5). State-dict key prefix is features.*.avgpoolnn.AdaptiveAvgPool2dfeature_infolist[FeatureInfo]BackboneMixin.Notes
From Huang et al., CVPR 2017. Each layer in a dense block computes
where is channel-wise concatenation and
is a BN → ReLU → Conv → BN → ReLU
→ Conv composite (the bottleneck variant used in
all ImageNet DenseNets). Each contributes
growth_rate new channels — typically — so the
input width of layer grows linearly as . Transition layers compress the channel count by
a factor of 2 between blocks. DenseNet-121 has only 8 M parameters
yet matches the accuracy of ResNet-50 (25 M parameters) on
ImageNet.
Examples
Build a DenseNet-121 backbone and run a single forward pass:
>>> import lucid
>>> from lucid.models.vision.densenet import densenet_121
>>> backbone = densenet_121()
>>> x = lucid.randn(2, 3, 224, 224)
>>> out = backbone(x)
>>> out.last_hidden_state.shape # (B, 1024, 1, 1)
(2, 1024, 1, 1)