2.1.1.1.1.4. emicroml.modelling.cbed.distortion.estimation.load_ml_model_from_state_dict
- load_ml_model_from_state_dict(ml_model_state_dict, device_name=None)[source]
Load a machine learning model from a dictionary
The current function loads machine learning (ML) models, represented by the class
emicroml.modelling.cbed.distortion.estimation.MLModel
, from dictionary representations of said ML models.Dictionary representations of ML models can be generated via the method
emicroml.modelling.cbed.distortion.estimation.MLModel.state_dict()
.Moreover, dictionary representations of ML models can be generated then saved to files via the method
emicroml.modelling.cbed.distortion.estimation.MLModelTrainer.train_ml_model()
of the classemicroml.modelling.cbed.distortion.estimation.MLModelTrainer
. For further details see the documentation for said method.Let
ml_model_state_dict_filename
be the relative or absolute path to a file storing a dictionary representation of an ML model of interest. One can load said dictionary representation via the functiontorch.load()
, where the function parameterf
should be set toml_model_state_dict_filename
. In this case, the functiontorch.load()
should return the dictionary representation. For further details see the documentation for the functiontorch.load()
.- Parameters:
- ml_model_state_dictdict
The dictionary representation of the ML model to load.
- device_namestr | None, optional
This parameter specifies the device in which to store the ML model. If
device_name
is a string, then it is the name of the device to be used, e.g.”cuda”
or”cpu”
. Ifdevice_name
is set toNone
and a GPU device is available, then a GPU device is to be used. Otherwise, the CPU is used.
- Returns:
- ml_model
emicroml.modelling.cbed.distortion.estimation.MLModel
The ML model represented by the dictionary
ml_model_state_dict
.
- ml_model