Skip to content
fn

register_weights

→Callable[[type[WeightsEnum]], type[WeightsEnum]]
register_weights(model_name: str)

Class decorator registering a WeightsEnum for discovery.

Parameters

model_namestr
The factory name the enum belongs to (e.g. "resnet_18").

Returns

Callable[[type[WeightsEnum]], type[WeightsEnum]]

A decorator that records the enum under both model_name (for list_pretrained) and the enum's class name (for get_weight), then returns the class unchanged.

Examples

>>> from lucid.utils.transforms import ImageClassification
>>> from lucid.weights import (
...     WeightEntry,
...     WeightsEnum,
...     register_weights,
...     weights_for,
... )
>>> @register_weights("my_net_cls")
... class MyNetWeights(WeightsEnum):
...     IMAGENET1K_V1 = WeightEntry(
...         url="https://example.com/my-net/IMAGENET1K_V1/model.safetensors",
...         sha256="0" * 64,
...         num_classes=1000,
...         transforms=ImageClassification(crop_size=224, resize_size=256),
...         meta={"tag": "IMAGENET1K_V1"},
...     )
...     DEFAULT = IMAGENET1K_V1
>>> weights_for("my_net_cls") is MyNetWeights
True

Used by 1