-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathh5_util.py
More file actions
26 lines (20 loc) · 704 Bytes
/
h5_util.py
File metadata and controls
26 lines (20 loc) · 704 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""
Serialization and deserialization of directions in the direction file.
"""
import torch
def write_list(f, name, direction):
""" Save the direction to the hdf5 file with name as the key
Args:
f: h5py file object
name: key name_surface_file
direction: a list of tensors
"""
grp = f.create_group(name)
for i, l in enumerate(direction):
if isinstance(l, torch.Tensor):
l = l.numpy()
grp.create_dataset(str(i), data=l)
def read_list(f, name):
""" Read group with name as the key from the hdf5 file and return a list numpy vectors. """
grp = f[name]
return [grp[str(i)] for i in range(len(grp))]