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

39 lines
1.7 KiB
ReStructuredText
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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文件。
**参数:**
- **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”。
**返回:**
字典key是参数名称value是Parameter类型。
**异常:**
**ValueError** checkpoint文件格式正确。
**样例:**
.. code-block::
>>> 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)