Exemplo n.º 1
0
    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.FrameIterator(['utt-1', 'utt-2', 'utt-3'], [cont],
                                   240,
                                   shuffle=True,
                                   seed=333))

        assert 7 == 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]), frames[1][0])
        assert np.allclose(([0.4, 0.4, 0.4, 0.4, 0.4]), frames[2][0])
        assert np.allclose(([0.2, 0.2, 0.2, 0.2, 0.2]), frames[3][0])
        assert np.allclose(([0.1, 0.1, 0.1, 0.1, 0.1]), frames[4][0])
        assert np.allclose(([0.6, 0.6, 0.6, 0.6, 0.6]), frames[5][0])
        assert np.allclose(([0.7, 0.7, 0.7, 0.7, 0.7]), frames[6][0])
Exemplo n.º 2
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.FrameIterator(['utt-1', 'utt-3'], [cont],
                                   120,
                                   shuffle=True,
                                   seed=1236))

        assert 4 == len(frames)

        assert np.allclose(([0.1, 0.1, 0.1, 0.1, 0.1]), frames[0][0])
        assert np.allclose(([0.2, 0.2, 0.2, 0.2, 0.2]), frames[1][0])
        assert np.allclose(([0.7, 0.7, 0.7, 0.7, 0.7]), frames[2][0])
        assert np.allclose(([0.6, 0.6, 0.6, 0.6, 0.6]), frames[3][0])
Exemplo n.º 3
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.FrameIterator([], [cont], 120))
        assert 0 == len(frames)
Exemplo n.º 4
0
    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.FrameIterator(['utt-1'], [cont], 120))
        assert 0 == len(frames)
Exemplo n.º 5
0
    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.FrameIterator(['utt-1', 'utt-2'], [cont],
                                   120,
                                   shuffle=False))
        assert 5 == len(frames)

        assert np.allclose(([0.1, 0.1, 0.1, 0.1, 0.1]), frames[0][0])
        assert np.allclose(([0.2, 0.2, 0.2, 0.2, 0.2]), frames[1][0])
        assert np.allclose(([0.3, 0.3, 0.3, 0.3, 0.3]), frames[2][0])
        assert np.allclose(([0.4, 0.4, 0.4, 0.4, 0.4]), frames[3][0])
        assert np.allclose(([0.5, 0.5, 0.5, 0.5, 0.5]), frames[4][0])