def save(self, filename):
"""
Save the state of this network to a pickle file on disk.
:param filename: Save the parameters of this network to a pickle file at the named path. If this name ends in
".gz" then the output will automatically be gzipped; otherwise the output will be a "raw" pickle.
:return: None
"""
state = dict([('class', self.__class__.__name__), ('network', self.__str__())])
for layer in self.layers:
key = '{}-values'.format(layer.layerNum)
state[key] = [p.get_value() for p in layer.params]
opener = gzip.open if filename.lower().endswith('.gz') else open
handle = opener(filename, 'wb')
cPickle.dump(state, handle, -1)
handle.close()
print 'Saved model parameter to {}'.format(filename)
评论列表
文章目录