mindspore/docs/api/api_python/mindspore.load_checkpoint.rst

32 lines
1.6 KiB
ReStructuredText
Raw Normal View History

2021-11-24 12:44:52 +08:00
mindspore.load_checkpoint
==========================
.. py:class:: mindspore.load_checkpoint(ckpt_file_name, net=None, strict_load=False, filter_prefix=None, dec_key=None, dec_mode="AES-GCM")
加载checkpoint文件。
**参数:**
2021-12-02 09:29:36 +08:00
- **ckpt_file_name** (str) checkpoint的文件名称。
- **net** (Cell) 加载checkpoint参数的网络。默认值None。
- **strict_load** (bool) 是否将严格加载参数到网络中。如果是False, 它将根据相同的后缀名将参数字典中的参数加载到网络中并会在精度不匹配时进行强制精度转换比如将float32转换为float16。默认值False。
- **filter_prefix** (Union[str, list[str], tuple[str]]) `filter_prefix` 开头的参数将不会被加载。默认值None。
- **dec_key** (Union[None, bytes]) 用于解密的字节类型密钥如果值为None则不需要解密。默认值None。
- **dec_mode** (str) 该参数仅当 `dec_key` 不为None时有效。指定解密模式目前支持“AES-GCM”和“AES-CBC”。默认值“AES-GCM”。
2021-11-24 12:44:52 +08:00
**返回:**
2021-12-02 09:29:36 +08:00
字典key是参数名称value是Parameter类型。
2021-11-24 12:44:52 +08:00
**异常:**
2021-12-02 09:29:36 +08:00
**ValueError** checkpoint文件格式正确。
2021-11-24 12:44:52 +08:00
**样例:**
2021-12-02 09:29:36 +08:00
>>> from mindspore import load_checkpoint
>>> ckpt_file_name = "./checkpoint/LeNet5-1_32.ckpt"
>>> param_dict = load_checkpoint(ckpt_file_name, filter_prefix="conv1")
>>> print(param_dict["conv2.weight"])
Parameter (name=conv2.weight, shape=(16, 6, 5, 5), dtype=Float32, requires_grad=True)