def save_model(self, path=''):
"""Save chainer model
Example:
::
path = './test.model'
self.save_model(path)
Args:
path (str): path
Returns:
bool: True if saving successful
"""
# if gpu_flag is True, switch the model to gpu mode at last
gpu_flag = False
# if gpu mode, switch the model to cpu mode temporarily
if self.model_is_cpu_mode() is False:
self.to_cpu()
gpu_flag = True
# if path is ''
if path == '':
path = str(self.save_model_epoch) + '.model'
self.nz_save_model_epoch += 1
# increment self.nz_save_model_epoch
serializers.save_npz(path, self)
# if gpu_flag is True, switch the model to gpu mode at last
if gpu_flag:
self.to_gpu()
return True
评论列表
文章目录