Skip to content
class

DenseNetForImageClassification

extendsImageClassificationModelClassificationHeadMixin
DenseNetForImageClassification(config: DenseNetConfig)

DenseNet image classifier (backbone + GAP + linear head).

Combines a DenseNet backbone with a global-average-pool and a single lucid.nn.Linear classifier producing config.num_classes logits. When labels are supplied to forward, a categorical cross-entropy loss is returned alongside the logits.

Parameters

Architecture spec. Use the *_cls factory functions (densenet_121_cls, densenet_169_cls, …) for the paper-cited variants.

Attributes

Stored copy of the config that built this model.
features_Features
Same dense feature stack as on DenseNet.
Global average pool to 1×11\times1.
classifiernn.Linear
Final linear projection features.num_features → num_classes.

Notes

From Huang et al., "Densely Connected Convolutional Networks", CVPR 2017. Loss is the standard categorical cross-entropy

L=−1N∑n=1Nlog⁡softmax⁡(logitsn) yn.\mathcal{L} = -\frac{1}{N} \sum_{n=1}^{N} \log \operatorname{softmax}(\text{logits}_n)_{\,y_n}.

DenseNet's parameter efficiency makes it particularly attractive for embedded / on-device deployment: DenseNet-121 reaches the same ImageNet top-1 accuracy as ResNet-50 with roughly one-third the parameter budget.

Examples

>>> import lucid
>>> from lucid.models.vision.densenet import densenet_121_cls
>>> model = densenet_121_cls()
>>> x = lucid.randn(2, 3, 224, 224)
>>> out = model(x)
>>> out.logits.shape
(2, 1000)

Used by 2

Constructors

1
dunder

__init__

→None
__init__(config: DenseNetConfig)

Instance methods

1