mindspore/docs/api/api_python/train/mindspore.train.BackupAndRe...

46 lines
2.1 KiB
ReStructuredText
Raw Normal View History

2022-10-14 22:50:18 +08:00
mindspore.train.BackupAndRestore
================================
.. py:class:: mindspore.train.BackupAndRestore(backup_dir, save_freq="epoch", delete_checkpoint=True)
在训练过程中备份和恢复训练参数的回调函数。
.. note::
只能在训练过程使用这个方法。
参数:
- **backup_dir** (str) - 保存和恢复checkpoint文件的路径。
- **save_freq** (Union['epoch', int]) - 当设置为'epoch'时在每个epoch进行备份当设置为整数时将在每隔 `save_freq` 个epoch进行备份。默认值'epoch'。
- **delete_checkpoint** (bool) - 如果 `delete_checkpoint=True` 将在训练结束的时候删除备份文件否则保留备份文件。默认值True。
异常:
- **ValueError** - 如果 `backup_dir` 参数不是str类型。
- **ValueError** - 如果 `save_freq` 参数不是'epoch'或str类型。
- **ValueError** - 如果 `delete_checkpoint` 参数不是bool类型。
2022-11-08 10:26:50 +08:00
样例:
.. note::
2022-11-09 11:33:30 +08:00
运行以下样例之前需自定义网络LeNet5和数据集准备函数create_dataset。详见 `网络构建 <https://www.mindspore.cn/tutorials/zh-CN/master/beginner/model.html>`_`数据集 Dataset <https://www.mindspore.cn/tutorials/zh-CN/master/beginner/dataset.html>`_
2022-11-08 10:26:50 +08:00
2022-10-14 22:50:18 +08:00
.. py:method:: on_train_begin(run_context)
在训练开始时加载备份的checkpoint文件。
参数:
- **run_context** (RunContext) - 包含模型的一些基本信息。详情请参考 :class:`mindspore.train.RunContext`
2022-10-19 11:10:29 +08:00
.. py:method:: on_train_end(run_context)
2022-10-14 22:50:18 +08:00
2022-10-19 11:10:29 +08:00
在训练结束时判断是否删除备份的checkpoint文件。
2022-10-14 22:50:18 +08:00
参数:
- **run_context** (RunContext) - 包含模型的一些基本信息。详情请参考 :class:`mindspore.train.RunContext`
2022-10-19 11:10:29 +08:00
.. py:method:: on_train_epoch_end(run_context)
2022-10-14 22:50:18 +08:00
2022-10-19 11:10:29 +08:00
在每个epoch结束时判断是否需要备份checkpoint文件。
2022-10-14 22:50:18 +08:00
参数:
2022-10-19 11:10:29 +08:00
- **run_context** (RunContext) - 包含模型的一些基本信息。详情请参考 :class:`mindspore.train.RunContext`