def test_with_statement():
    FeatureExtractor(store=True, overwrite=True).extract(
        audio_file=os.path.join('material', 'test.wav'),
        extractor_name='mfcc',
        extractor_params={
            'mfcc': {
                'n_mfcc': 10
            }
        },
        storage_paths={
            'mfcc': os.path.join('material', 'test.mfcc.cpickle')
        }
    )

    feature_container = FeatureContainer().load(filename=os.path.join('material', 'test.mfcc.cpickle'))
    with FeatureNormalizer() as feature_normalizer:
        feature_normalizer.accumulate(feature_container)

    nose.tools.eq_(feature_normalizer['N'][0], 501)

    numpy.testing.assert_array_equal(feature_normalizer['mean'][0][0],
                                     numpy.mean(feature_container.feat[0], axis=0))
    numpy.testing.assert_array_equal(feature_normalizer['S1'][0],
                                     numpy.sum(feature_container.feat[0], axis=0))
    numpy.testing.assert_array_equal(feature_normalizer['S2'][0],
                                     numpy.sum(feature_container.feat[0] ** 2, axis=0))

    test_accumulate_finalize()
コード例 #2
0
def test_normalizer():
    FeatureExtractor(store=True, overwrite=True).extract(
        audio_file=os.path.join('material', 'test.wav'),
        extractor_name='mfcc',
        extractor_params={'mfcc': {
            'n_mfcc': 10
        }},
        storage_paths={'mfcc': os.path.join('material', 'test.mfcc.cpickle')})

    # Test 1
    test_recipe = 'mfcc=0-5'
    test_recipe_parsed = ParameterContainer()._parse_recipe(recipe=test_recipe)
    feature_container = FeatureContainer().load(
        filename=os.path.join('material', 'test.mfcc.cpickle'))
    feature_normalizer = FeatureNormalizer().accumulate(
        feature_container=feature_container).finalize()

    feature_stacker = FeatureStacker(recipe=test_recipe_parsed)
    feature_normalizer = feature_stacker.normalizer(
        normalizer_list={'mfcc': feature_normalizer})

    nose.tools.eq_(feature_normalizer['N'][0][0], 501)
    nose.tools.eq_(feature_normalizer['mean'][0].shape[0], 1)
    nose.tools.eq_(feature_normalizer['mean'][0].shape[1], 6)

    nose.tools.eq_(feature_normalizer['std'][0].shape[0], 1)
    nose.tools.eq_(feature_normalizer['std'][0].shape[1], 6)

    # Test 2
    test_recipe = 'mfcc=1,2,3,4'
    test_recipe_parsed = ParameterContainer()._parse_recipe(recipe=test_recipe)
    feature_container = FeatureContainer().load(
        filename=os.path.join('material', 'test.mfcc.cpickle'))
    feature_normalizer = FeatureNormalizer().accumulate(
        feature_container=feature_container).finalize()

    feature_stacker = FeatureStacker(recipe=test_recipe_parsed)
    feature_normalizer = feature_stacker.normalizer(
        normalizer_list={'mfcc': feature_normalizer})

    nose.tools.eq_(feature_normalizer['N'][0][0], 501)
    nose.tools.eq_(feature_normalizer['mean'][0].shape[0], 1)
    nose.tools.eq_(feature_normalizer['mean'][0].shape[1], 4)

    nose.tools.eq_(feature_normalizer['std'][0].shape[0], 1)
    nose.tools.eq_(feature_normalizer['std'][0].shape[1], 4)

    # Test 3
    test_recipe = 'mfcc'
    test_recipe_parsed = ParameterContainer()._parse_recipe(recipe=test_recipe)
    feature_container = FeatureContainer().load(
        filename=os.path.join('material', 'test.mfcc.cpickle'))
    feature_normalizer = FeatureNormalizer().accumulate(
        feature_container=feature_container).finalize()

    feature_stacker = FeatureStacker(recipe=test_recipe_parsed)
    feature_normalizer = feature_stacker.normalizer(
        normalizer_list={'mfcc': feature_normalizer})

    nose.tools.eq_(feature_normalizer['N'][0][0], 501)
    nose.tools.eq_(feature_normalizer['mean'][0].shape[0], 1)
    nose.tools.eq_(feature_normalizer['mean'][0].shape[1], 10)

    nose.tools.eq_(feature_normalizer['std'][0].shape[0], 1)
    nose.tools.eq_(feature_normalizer['std'][0].shape[1], 10)