Skip to content
fn

densenet_121_cls

→DenseNetForImageClassification8M
densenet_121_cls(pretrained: bool | str = False, weights: DenseNet121Weights | None = None, overrides: object = {})

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

Builds a DenseNetForImageClassification with the paper-cited DenseNet-121 topology and a single lucid.nn.Linear classifier projecting 1024 → config.num_classes. Approximately 8.0 M parameters; top-1 ImageNet accuracy 74.43% (reference_vision weights).

Model Size

Parameters

pretrainedbool or str= False
False → random init; True → DEFAULT tag; a tag string → that checkpoint.
weights(DenseNet121Weights, optional, keyword - only)= None
Explicit enum member; takes precedence over pretrained.
**overridesobject= {}
Keyword overrides forwarded into DenseNetConfig.

Returns

DenseNetForImageClassification

Classifier with the DenseNet-121 configuration applied (or with overrides merged on top of it), optionally initialised from pretrained weights.

Examples

>>> import lucid
>>> from lucid.models.vision.densenet import densenet_121_cls
>>> model = densenet_121_cls(num_classes=100)
>>> x = lucid.randn(2, 3, 224, 224)
>>> out = model(x)
>>> out.logits.shape
(2, 100)
Load ImageNet-pretrained weights:
>>> model = densenet_121_cls(pretrained=True)
>>> from lucid.models.weights import DenseNet121Weights
>>> model = densenet_121_cls(weights=DenseNet121Weights.IMAGENET1K_V1)

Used by 1