mindspore.load_param_into_net
- mindspore.load_param_into_net(net, parameter_dict, strict_load=False, remove_redundancy=False)[source]
Load parameters into the network, and return the list of parameters that are not loaded.
Note
When loading a parameter dict that has removed redundancy, the network should be compiled.
- Parameters
net (Cell) – The network where the parameters will be loaded.
parameter_dict (dict) – The dictionary generated by load checkpoint file, it is a dictionary consisting of key as parameter name and value as parameter.
strict_load (bool, optional) – Whether to strictly load the parameter into net. If
False, it will load parameter into net when parameter name's suffix in checkpoint file is the same as the parameter in the network. When the types are inconsistent perform type conversion on the parameters of the same type, such as float32 to float16. Default:False.remove_redundancy (bool, optional) – Whether to enable loading of checkpoint saved with redundancy removal. Redundancy removal refers to eliminating redundant data in data parallelism mode. Default:
False, means redundant-free loading is not enabled.
- Returns
param_not_load (List), the parameter names in the model that are not loaded into the network.
ckpt_not_load (List), the parameter names in the checkpoint file that are not loaded into the network.
- Raises
TypeError – Argument is not a Cell, or parameter_dict is not a Parameter dictionary.
Examples
>>> import mindspore as ms >>> >>> # Define the network structure of LeNet5. Refer to >>> # https://atomgit.com/mindspore/docs/blob/master/docs/mindspore/code/lenet.py >>> net = LeNet5() >>> ckpt_file_name = "./checkpoint/LeNet5-1_32.ckpt" >>> param_dict = ms.load_checkpoint(ckpt_file_name, filter_prefix="conv1") >>> param_not_load, _ = ms.load_param_into_net(net, param_dict) >>> print(param_not_load) ['conv1.weight']
- Tutorial Examples: