States
States are managed with two concepts:
StateType
: Represents a family of states that are compatible with each other. In general, a model can be loaded with any pre-trained state if it matches itsstate_type
attribute.StateKey
: The identifier of a state instance, it should uniquely identify the result of a training activity for a model.
mozuma.states.StateType
dataclass
Definition for a type of state
A state type is used to identify states that can be re-used accross models.
For instance, the weights from ResNet18 with 1000 classes pretrained on ImageNet can be reused to initialised the weights of a ResNet18 for binary classification. In this scenario, the state type of the ResNet trained on ImageNet can be re-used to partially initialize the binary classification ResNet18.
This is also used for models like key-frames extraction. Key-frames extraction does not define a new weights architecture, it is a wrapper around an image encoder. Therefore, any state that can be loaded into the image encoder, can also be loaded into the key-frame extractor. They share the same state type.
As a convention, two state types are compatible when backend
and architecture
attributes are the same. This is implemented in the
is_compatible_with
method.
Warning
All string attributes must match the VALID_NAMES
pattern.
Attributes:
Name | Type | Description |
---|---|---|
backend |
str |
The model backend. For instance |
architecture |
str |
Identifier for the architecture (e.g. |
extra |
tuple[str, ...] |
Additional information to identify architecture variants (number of output classes...). |
is_compatible_with(self, other: StateType) -> bool
Tells whether two architecture are compatible with each other.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other |
StateType |
The other architecture to compare |
required |
Returns:
Type | Description |
---|---|
bool |
|
mozuma.states.StateKey
dataclass
Identifier for a state of a trained model
Warning
All string attributes must match the VALID_NAMES
pattern.
Attributes:
Name | Type | Description |
---|---|---|
state_type |
StateType |
Identifies the type of state |
training_id |
str |
Identifies the training activity that was used to get to this state. |
mozuma.states.VALID_NAMES
The pattern for valid architecture name in
StateType.architecture
.
It must be alphanumeric characters separated with dashes (i.e. [\w\-\d]
)