ding.data.model_loader¶
ding.data.model_loader
¶
ModelLoader
¶
Bases: Supervisor, ABC
__init__(model)
¶
Overview
Save and send models asynchronously and load them synchronously.
Arguments:
- model (:obj:torch.nn.Module): Torch module.
load(storage)
¶
Overview
Load model synchronously.
Arguments:
- storage (:obj:Stroage): The model should be wrapped in a storage object, e.g. FileModelStorage.
Returns:
- object (:obj:): The loaded model.
save(callback)
abstractmethod
¶
Overview
Save model asynchronously.
Arguments:
- callback (:obj:Callable): The callback function after saving model.
Returns:
- storage (:obj:Storage): The storage object is created synchronously, so it can be returned.
FileModelLoader
¶
Bases: ModelLoader
__init__(model, dirname, ttl=20)
¶
Overview
Model loader using files as storage media.
Arguments:
- model (:obj:torch.nn.Module): Torch module.
- dirname (:obj:str): The directory for saving files.
- ttl (:obj:int): Files will be automatically cleaned after ttl. Note that files that do not time out when the process is stopped are not cleaned up (to avoid errors when other processes read the file), so you may need to clean up the remaining files manually
Full Source Code
../ding/data/model_loader.py