Skip to content
class

WeightsEnum

extendsEnum
WeightsEnum()

Base class for per-architecture pretrained-weight enums.

Each architecture subclasses WeightsEnum and lists its tagged checkpoints as members whose values are WeightEntry instances:

class ResNet18Weights(WeightsEnum):
    IMAGENET1K_V1 = WeightEntry(url=..., sha256=..., ...)
    DEFAULT = IMAGENET1K_V1

Members expose the underlying entry's fields directly (ResNet18Weights.IMAGENET1K_V1.url) plus the tag name (.tag), so call sites read naturally. Assigning DEFAULT = IMAGENET1K_V1 makes DEFAULT an alias of the canonical member (standard enum behaviour for duplicate values), exactly mirroring the reference_vision convention where DEFAULT tracks the strongest available weights.

Notes

The enum.Enum value of each member is a frozen WeightEntry. Accessing .value returns that entry; the convenience properties below forward to it.

Used by 3

Properties

6
prop

meta

→dict[str, object]
meta: dict[str, object]

Provenance + metrics dict (see WeightEntry.meta).

prop

num_classes

→int
num_classes: int

Output-class count of this checkpoint's head.

prop

sha256

→str
sha256: str

Expected SHA-256 of this checkpoint.

prop

tag

→str
tag: str

The variant tag (member name), e.g. "IMAGENET1K_V1".

For the DEFAULT alias this resolves to the canonical member's name (the one it aliases), not the literal string "DEFAULT".

prop

url

→str
url: str

Download URL of this checkpoint (see WeightEntry.url).

Instance methods

1
fn

transforms

→Transform
transforms()

Return the preprocessing pipeline the weights expect.

Returns

Transform

Callable transform; apply to a lucid.Tensor image before feeding the model.

Examples

>>> import lucid
>>> import lucid.models              # registers the zoo's weights enums
>>> import lucid.weights as W
>>> ResNet18Weights = W.weights_for("resnet_18_cls")
>>> weights = ResNet18Weights.IMAGENET1K_V1
>>> preprocess = weights.transforms()
>>> image = lucid.rand(3, 300, 400)
>>> x = preprocess(image)        # image: lucid.Tensor (C, H, W)
>>> x.shape
(3, 224, 224)
>>> model = lucid.models.resnet_18_cls().eval()
>>> logits = model(x[None]).logits
>>> logits.shape
(1, 1000)