-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
95fdda3
commit e56dbf7
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import h5py | ||
import numpy as np | ||
from typing import Dict | ||
|
||
|
||
def get_input_dict_from_returnn_hdf(hdf_file: h5py.File) -> Dict[str, np.ndarray]: | ||
""" | ||
Generate dictionary containing the "data" value as ndarray indexed by the sequence tag | ||
:param hdf_file: HDF file to extract data from | ||
:return: | ||
""" | ||
inputs = hdf_file["inputs"] | ||
seq_tags = hdf_file["seqTags"] | ||
lengths = hdf_file["seqLengths"] | ||
|
||
output_dict = {} | ||
offset = 0 | ||
for tag, length in zip(seq_tags, lengths): | ||
tag = tag if isinstance(tag, str) else tag.decode() | ||
output_dict[tag] = inputs[offset : offset + length[0]] | ||
offset += length[0] | ||
|
||
return output_dict |