in utils/io.py [0:0]
def write_h5(path, data):
"""Write h5 file
Arguments:
path {str} -- file path where to save the data
data {seriaizable} -- data to be saved
Raises:
NotImplementedError -- non serializable data to save
"""
if '.h5' not in path[-3:]:
path += '.h5'
hf = h5py.File(path, 'w')
if isinstance(data, dict):
for k, v in data.items():
if isinstance(v[0], str):
v = [a.encode('utf8') for a in v]
hf.create_dataset(k, data=v)
elif isinstance(data, list):
hf.create_dataset('val', data=data)
elif isinstance(data, np.ndarray):
hf.create_dataset('val', data=data)
else:
raise NotImplementedError
hf.close()