def save_params(self, tofile):
"""
Save params to disk, compatible with fromfile option of constructor.
If argument is a string, a new file is with that name is written to.
If argument is a file handle, data is written to that.
"""
is_handle = type(tofile) == file
save_file = tofile if is_handle else open(tofile, 'wb')
for variable in self.params.values():
cPickle.dump(variable.eval(), save_file, -1)
for attr in type(self).attr_names:
cPickle.dump(getattr(self, attr), save_file, -1)
if not is_handle: save_file.close()
评论列表
文章目录