def test_next_emits_chunks_with_length(self, tmpdir): ds1 = np.array([[0.1, 0.1, 0.1, 0.1, 0.1], [0.2, 0.2, 0.2, 0.2, 0.2]]) ds2 = np.array([[0.3, 0.3, 0.3, 0.3, 0.3], [0.4, 0.4, 0.4, 0.4, 0.4], [0.5, 0.5, 0.5, 0.5, 0.5]]) ds3 = np.array([[0.6, 0.6, 0.6, 0.6, 0.6]]) file_path = os.path.join(tmpdir.strpath, 'features.h5') cont = containers.Container(file_path) cont.open() cont.set('utt-1', ds1) cont.set('utt-2', ds2) cont.set('utt-3', ds3) frames = tuple( iterator.MultiFrameIterator(['utt-1', 'utt-2', 'utt-3'], [cont], 120, 2, return_length=True, shuffle=True, seed=6)) assert 4 == len(frames) assert np.allclose(([[0.5, 0.5, 0.5, 0.5, 0.5]]), frames[0][0]) assert np.allclose( ([[0.3, 0.3, 0.3, 0.3, 0.3], [0.4, 0.4, 0.4, 0.4, 0.4]]), frames[1][0]) assert np.allclose(([[0.6, 0.6, 0.6, 0.6, 0.6]]), frames[2][0]) assert np.allclose( ([[0.1, 0.1, 0.1, 0.1, 0.1], [0.2, 0.2, 0.2, 0.2, 0.2]]), frames[3][0]) assert frames[0][1] == 1 assert frames[1][1] == 2 assert frames[2][1] == 1 assert frames[3][1] == 2
def test_next_emits_all_features_if_partition_spans_multiple_data_sets_in_random_order( self, tmpdir): ds1 = np.array([[0.1, 0.1, 0.1, 0.1, 0.1], [0.2, 0.2, 0.2, 0.2, 0.2]]) ds2 = np.array([[0.3, 0.3, 0.3, 0.3, 0.3], [0.4, 0.4, 0.4, 0.4, 0.4], [0.5, 0.5, 0.5, 0.5, 0.5]]) ds3 = np.array([[0.6, 0.6, 0.6, 0.6, 0.6], [0.7, 0.7, 0.7, 0.7, 0.7]]) file_path = os.path.join(tmpdir.strpath, 'features.h5') cont = containers.Container(file_path) cont.open() cont.set('utt-1', ds1) cont.set('utt-2', ds2) cont.set('utt-3', ds3) frames = tuple( iterator.MultiFrameIterator(['utt-1', 'utt-2', 'utt-3'], [cont], 240, 2, shuffle=True, seed=12)) assert 4 == len(frames) assert np.allclose(([[0.5, 0.5, 0.5, 0.5, 0.5]]), frames[0][0]) assert np.allclose( ([[0.3, 0.3, 0.3, 0.3, 0.3], [0.4, 0.4, 0.4, 0.4, 0.4]]), frames[1][0]) assert np.allclose( ([[0.1, 0.1, 0.1, 0.1, 0.1], [0.2, 0.2, 0.2, 0.2, 0.2]]), frames[2][0]) assert np.allclose( ([[0.6, 0.6, 0.6, 0.6, 0.6], [0.7, 0.7, 0.7, 0.7, 0.7]]), frames[3][0])
def test_next_emits_features_only_from_included_ds_in_random_order( self, tmpdir): ds1 = np.array([[0.1, 0.1, 0.1, 0.1, 0.1], [0.2, 0.2, 0.2, 0.2, 0.2]]) ds2 = np.array([[0.3, 0.3, 0.3, 0.3, 0.3], [0.4, 0.4, 0.4, 0.4, 0.4], [0.5, 0.5, 0.5, 0.5, 0.5]]) ds3 = np.array([[0.6, 0.6, 0.6, 0.6, 0.6], [0.7, 0.7, 0.7, 0.7, 0.7]]) file_path = os.path.join(tmpdir.strpath, 'features.h5') cont = containers.Container(file_path) cont.open() cont.set('utt-1', ds1) cont.set('utt-2', ds2) cont.set('utt-3', ds3) frames = tuple( iterator.MultiFrameIterator(['utt-1', 'utt-3'], [cont], 120, 2, shuffle=True, seed=1)) assert 2 == len(frames) assert np.allclose( ([[0.6, 0.6, 0.6, 0.6, 0.6], [0.7, 0.7, 0.7, 0.7, 0.7]]), frames[0][0]) assert np.allclose( ([[0.1, 0.1, 0.1, 0.1, 0.1], [0.2, 0.2, 0.2, 0.2, 0.2]]), frames[1][0])
def test_next_emits_no_frames_if_file_is_empty(self, tmpdir): file_path = os.path.join(tmpdir.strpath, 'features.h5') cont = containers.Container(file_path) cont.open() frames = tuple(iterator.MultiFrameIterator([], [cont], '120', 5)) assert 0 == len(frames)
def test_next_emits_no_features_if_data_set_is_empty(self, tmpdir): file_path = os.path.join(tmpdir.strpath, 'features.h5') cont = containers.Container(file_path) cont.open() cont.set('utt-1', np.array([])) frames = tuple(iterator.MultiFrameIterator(['utt-1'], [cont], '120', 5)) assert 0 == len(frames)
def test_next_emits_all_features_in_sequential_order(self, tmpdir): ds1 = np.array([[0.1, 0.1, 0.1, 0.1, 0.1], [0.2, 0.2, 0.2, 0.2, 0.2]]) ds2 = np.array([[0.3, 0.3, 0.3, 0.3, 0.3], [0.4, 0.4, 0.4, 0.4, 0.4], [0.5, 0.5, 0.5, 0.5, 0.5]]) file_path = os.path.join(tmpdir.strpath, 'features.h5') cont = containers.Container(file_path) cont.open() cont.set('utt-1', ds1) cont.set('utt-2', ds2) frames = tuple( iterator.MultiFrameIterator(['utt-1', 'utt-2'], [cont], '120', 5, shuffle=False)) assert 2 == len(frames) assert np.allclose( ([[0.1, 0.1, 0.1, 0.1, 0.1], [0.2, 0.2, 0.2, 0.2, 0.2]]), frames[0][0]) assert np.allclose( ([[0.3, 0.3, 0.3, 0.3, 0.3], [0.4, 0.4, 0.4, 0.4, 0.4], [0.5, 0.5, 0.5, 0.5, 0.5]]), frames[1][0])