Skip to content

Instantly share code, notes, and snippets.

@marcromeyn
Created February 10, 2016 08:24
Show Gist options
  • Select an option

  • Save marcromeyn/ea450dcd58cbe1bd3cad to your computer and use it in GitHub Desktop.

Select an option

Save marcromeyn/ea450dcd58cbe1bd3cad to your computer and use it in GitHub Desktop.
def save_file(filepath):
f = h5py.File(filepath, 'w')
f.attrs['nb_documents'] = len(self.layers)
for k, l in enumerate(self.layers):
g = f.create_group('doc_{}'.format(k))
weights = l.get_weights()
g.attrs['nb_params'] = len(weights)
for n, param in enumerate(weights):
param_name = 'param_{}'.format(n)
param_dset = g.create_dataset(param_name, param.shape,
dtype=param.dtype)
param_dset[:] = param
f.flush()
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment