Skip to content
fn

resolve_weights

→WeightsEnum or None
resolve_weights(enum_cls: type[WeightsEnum], pretrained: bool | str, weights: WeightsEnum | None)

Resolve a factory's pretrained / weights args to a member.

Implements the shared selection logic every pretrained factory uses, so the three call styles all funnel to one enum member (or None for random init).

Parameters

enum_clstype[WeightsEnum]
The architecture's weights enum (e.g. ResNet18Weights).
pretrainedbool or str
False → no weights; True → the DEFAULT tag; a string → that specific tag (e.g. "IMAGENET1K_V1").
weightsWeightsEnum or None
An explicit enum member. Takes precedence over pretrained when given.

Returns

WeightsEnum or None

The selected member, or None for random initialisation.

Raises

TypeError
If weights is from a different enum than enum_cls, or pretrained is neither bool nor str.
ValueError
If a string tag is not a member of enum_cls.

Used by 1