nvflare.app_common.abstract.model_persistor module¶
- class ModelPersistor(filter_id: str | None = None)[source]¶
Bases:
LearnablePersistor
,ABC
Abstract class. Implementations will need to implement the load_model() and save_model() methods to persist & load the current ModelLearnable.
- Parameters:
filter_id – Optional string that defines a filter component that is applied to prepare the model to be saved, e.g. for serialization of custom Python objects.
- get_model(model_file: str, fl_ctx: FLContext) ModelLearnable [source]¶
- get_model_inventory(fl_ctx: FLContext) Dict[str, ModelDescriptor] [source]¶
Get the model inventory of the ModelPersister.
- Parameters:
fl_ctx – FLContext
- Returns:
ModelDescriptor
- Return type:
A dict of model_name
- load(fl_ctx: FLContext) ModelLearnable [source]¶
Load the Learnable object.
- Parameters:
fl_ctx – FLContext
- Returns:
Learnable object loaded
- abstract load_model(fl_ctx: FLContext) ModelLearnable [source]¶
Initialize and load the model.
- Parameters:
fl_ctx – FLContext
- Returns:
Model object
- save(learnable: ModelLearnable, fl_ctx: FLContext)[source]¶
Persist the Learnable object.
- Parameters:
learnable – the Learnable object to be saved
fl_ctx – FLContext
- abstract save_model(model: ModelLearnable, fl_ctx: FLContext)[source]¶
Persist the model object.
- Parameters:
model – Model object to be saved
fl_ctx – FLContext