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 strFalse → no weights; True → the DEFAULT tag; a string
→ that specific tag (e.g. "IMAGENET1K_V1").weightsWeightsEnum or NoneAn explicit enum member. Takes precedence over
pretrained
when given.Returns
WeightsEnum or NoneThe selected member, or None for random initialisation.
Raises
TypeErrorIf
weights is from a different enum than enum_cls, or
pretrained is neither bool nor str.ValueErrorIf a string tag is not a member of
enum_cls.