resnet_18_cls(pretrained: bool | str = False, weights: ResNet18Weights | None = None, overrides: object = {})ResNet-18 image classifier (backbone + GAP + linear head).
Builds a ResNetForImageClassification with the paper-cited
ResNet-18 topology: _BasicBlock blocks stacked
[2, 2, 2, 2] over four stages, followed by global average
pooling and a linear projection to config.num_classes
(default 1000 for ImageNet-1k). Approximately 11.7M parameters
and 69.76% ImageNet-1k top-1 in He et al., 2015 (Table 4).
Model Size
Parameters
pretrainedbool or str= FalseFalse → random init; True
→ the DEFAULT tag (ResNet18Weights.IMAGENET1K_V1);
a tag string (e.g. "IMAGENET1K_V1") → that specific
checkpoint. Mutually exclusive with weights (which wins if
both are given).ResNet18Weights.IMAGENET1K_V1. Takes precedence over
pretrained.**overridesobject= {}ResNetConfig
(typically num_classes to retarget the classifier or
dropout to inject regularisation before the linear head).
Note: overriding num_classes away from the checkpoint's
class count makes pretrained loading fail the strict key/shape
check — load with a matching head, then call
reset_classifier.Returns
ResNetForImageClassificationClassifier with the ResNet-18 configuration applied (or with
overrides merged on top of it), optionally initialised from
pretrained weights.
Notes
See He et al., "Deep Residual Learning for Image Recognition",
CVPR 2016 (arXiv:1512.03385), Table 1. Pretrained weights are
converted from torchvision's ResNet18_Weights and hosted on the
Hugging Face Hub under lucid-dl/resnet-18.
Examples
>>> import lucid
>>> from lucid.models.vision.resnet import resnet_18_cls
>>> model = resnet_18_cls(num_classes=10)
>>> x = lucid.randn(2, 3, 224, 224)
>>> out = model(x)
>>> out.logits.shape
(2, 10)
Load ImageNet-pretrained weights:
>>> model = resnet_18_cls(pretrained=True) # DEFAULT tag
>>> from lucid.models.vision.resnet import ResNet18Weights
>>> model = resnet_18_cls(weights=ResNet18Weights.IMAGENET1K_V1)