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% (torchvision weights).
Model Size
Parameters
pretrainedbool or str= FalseFalse → random init; True → DEFAULT tag; a tag
string → that checkpoint.Explicit enum member; takes precedence over
pretrained.**overridesobject= {}Keyword overrides forwarded into
DenseNetConfig.Returns
DenseNetForImageClassificationClassifier 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)