mindspore/docs/api/api_python/train/mindspore.train.ModelCheckp...

42 lines
1.6 KiB
ReStructuredText
Raw Normal View History

mindspore.train.ModelCheckpoint
===============================
2022-05-10 11:59:45 +08:00
.. py:class:: mindspore.train.ModelCheckpoint(prefix='CKP', directory=None, config=None)
2021-12-02 09:29:36 +08:00
checkpoint的回调函数。
2022-01-13 16:18:53 +08:00
在训练过程中调用该方法可以保存网络参数。
2021-12-02 09:29:36 +08:00
2021-12-04 20:36:47 +08:00
.. note::
2021-12-02 09:29:36 +08:00
在分布式训练场景下请为每个训练进程指定不同的目录来保存checkpoint文件。否则可能会训练失败。
2022-03-15 21:56:44 +08:00
如何在 `model` 方法中使用此回调函数默认将会把优化器中的参数保存到checkpoint文件中。
2021-12-02 09:29:36 +08:00
2022-07-21 10:30:12 +08:00
参数:
- **prefix** (str) - checkpoint文件的前缀名称。默认值'CKP'。
- **directory** (str) - 保存checkpoint文件的文件夹路径。默认情况下文件保存在当前目录下。默认值None。
- **config** (CheckpointConfig) - checkpoint策略配置。默认值None。
2021-12-04 20:36:47 +08:00
2022-07-21 10:30:12 +08:00
异常:
- **ValueError** - 如果prefix参数不是str类型或包含'/'字符。
- **ValueError** - 如果directory参数不是str类型。
- **TypeError** - config不是CheckpointConfig类型。
2022-01-13 16:18:53 +08:00
2021-12-02 09:29:36 +08:00
.. py:method:: end(run_context)
在训练结束后会保存最后一个step的checkpoint。
2022-07-21 10:30:12 +08:00
参数:
- **run_context** (RunContext) - 包含模型的一些基本信息。
2021-12-02 09:29:36 +08:00
.. py:method:: latest_ckpt_file_name
:property:
返回最新的checkpoint路径和文件名。
.. py:method:: step_end(run_context)
在step结束时保存checkpoint。
2022-07-21 10:30:12 +08:00
参数:
- **run_context** (RunContext) - 包含模型的一些基本信息。