Callbacks
Callbacks are used to control to control how a runner handles the results (features, labels or model weights).
They are classes implementing a pre-defined set of functions:
In memory callbacks
These callbacks accumulate results in-memory. They expose their results via object attributes.
mozuma.callbacks.memory.CollectFeaturesInMemory
dataclass
Callback to collect features in memory
Attributes:
Name | Type | Description |
---|---|---|
indices |
list |
List of dataset indices |
features |
numpy.ndarray |
Array of features.
The first dimension correspond to |
Note
This callback works with any array-like features
save_features(self, model: Any, indices: Sequence, features: Union[torch.Tensor, numpy.ndarray]) -> None
Save features output returned by a module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Any |
The MoZuMa model that produced the features |
required |
indices |
Sequence |
The list of indices as defined by the dataset |
required |
features |
ArrayLike |
The feature object as returned by the model |
required |
mozuma.callbacks.memory.CollectLabelsInMemory
dataclass
Callback to collect labels in memory
Attributes:
Name | Type | Description |
---|---|---|
indices |
list |
List of dataset indices |
label_scores |
numpy.ndarray |
Array of label scores.
The first dimension correspond to |
labels |
list[str] |
List of matching labels (label with maximum score) |
Note
This callback works with any array-like features
save_label_scores(self, model: ModelWithLabels, indices: Sequence, labels_scores: Union[torch.Tensor, numpy.ndarray]) -> None
Save labels scores returned by a module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
ModelWithLabels |
The MoZuMa model that produced the label scores |
required |
indices |
Sequence |
The list of indices as defined by the dataset |
required |
labels_scores |
ArrayLike |
Contains the output score/probability for each label |
required |
mozuma.callbacks.memory.CollectBoundingBoxesInMemory
dataclass
Callback to collect bounding boxes predictions in memory
Attributes:
Name | Type | Description |
---|---|---|
indices |
list |
List of dataset indices |
frames |
list[BatchVideoFramesPrediction[np.ndarray]] |
Sequence of video frames.
The first dimension correspond to |
Note
This callback works with any array-like features
save_bounding_boxes(self, model: Any, indices: Sequence, bounding_boxes: Sequence[mozuma.predictions.BatchBoundingBoxesPrediction[Union[torch.Tensor, numpy.ndarray]]]) -> None
Save bounding boxes output of a module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Any |
The model that produces the bounding boxes |
required |
indices |
Sequence |
The list of indices as defined by the dataset |
required |
bounding_boxes |
Sequence[BatchBoundingBoxesPrediction[_ContraArrayType]] |
The sequence bounding predictions |
required |
mozuma.callbacks.memory.CollectVideoFramesInMemory
dataclass
Callback to collect video frames in memory
Attributes:
Name | Type | Description |
---|---|---|
indices |
list |
List of dataset indices |
frames |
list[BatchVideoFramesPrediction[np.ndarray]] |
Sequence of video frames.
The first dimension correspond to |
Note
This callback works with any array-like features
save_frames(self, model: Any, indices: Sequence, frames: Sequence[mozuma.predictions.BatchVideoFramesPrediction[Union[torch.Tensor, numpy.ndarray]]]) -> None
Save frames extracted from a video
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Any |
The model that produces the video frames encoding |
required |
indices |
Sequence |
The list of indices as defined by the dataset |
required |
frames |
Sequence[BatchVideoFramesPrediction[_ArrayType]] |
The sequence of frame features and indices |
required |
Callbacks for training
mozuma.callbacks.states.SaveModelState
dataclass
Simple callback to save model state during training.
If state are saved during training (every X epochs,
see TorchTrainingOptions
)
the current epoch number is appended to the state_key.training_id
in the
following way: <state_key.training_id>-e<num_epoch>
.
When the training is complete, just the state_key.training_id
is used.
Attributes:
Name | Type | Description |
---|---|---|
store |
AbstractStateStore |
Object to handle model state saving |
state_key |
StateKey |
State identifier for the training activity. |
Warning
This callback only saves the model state, thus does not create a whole training checkpoint (optimizer state, loss, etc..).
save_model_state(self, engine: Engine, model: Any) -> None
Save model state by calling the state store
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Any |
The model to save |
required |
Write your own callbacks
mozuma.callbacks.base.BaseSaveFeaturesCallback
save_features(self, model: Any, indices: Sequence, features: -_ContraArrayType) -> None
Save features output returned by a module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Any |
The MoZuMa model that produced the features |
required |
indices |
Sequence |
The list of indices as defined by the dataset |
required |
features |
ArrayLike |
The feature object as returned by the model |
required |
mozuma.callbacks.base.BaseSaveLabelsCallback
save_label_scores(self, model: ModelWithLabels, indices: Sequence, labels_scores: -_ContraArrayType) -> None
Save labels scores returned by a module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
ModelWithLabels |
The MoZuMa model that produced the label scores |
required |
indices |
Sequence |
The list of indices as defined by the dataset |
required |
labels_scores |
ArrayLike |
Contains the output score/probability for each label |
required |
mozuma.callbacks.base.BaseSaveBoundingBoxCallback
save_bounding_boxes(self, model: Any, indices: Sequence, bounding_boxes: Sequence[mozuma.predictions.BatchBoundingBoxesPrediction[-_ContraArrayType]]) -> None
Save bounding boxes output of a module
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Any |
The model that produces the bounding boxes |
required |
indices |
Sequence |
The list of indices as defined by the dataset |
required |
bounding_boxes |
Sequence[BatchBoundingBoxesPrediction[_ContraArrayType]] |
The sequence bounding predictions |
required |
mozuma.callbacks.base.BaseSaveVideoFramesCallback
save_frames(self, model: Any, indices: Sequence, frames: Sequence[mozuma.predictions.BatchVideoFramesPrediction[-_ContraArrayType]]) -> None
Save frames extracted from a video
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Any |
The model that produces the video frames encoding |
required |
indices |
Sequence |
The list of indices as defined by the dataset |
required |
frames |
Sequence[BatchVideoFramesPrediction[_ArrayType]] |
The sequence of frame features and indices |
required |
mozuma.callbacks.base.BaseRunnerEndCallback
on_runner_end(self, model: Any) -> None
Called when the runner finishes
This can be used to do clean up. For instance if the data is being processed by a thread, this function can wait for the thread to finish.$
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
Any |
The currently run model |
required |