-
Notifications
You must be signed in to change notification settings - Fork 269
Expand file tree
/
Copy pathtest_features_key.py
More file actions
55 lines (41 loc) · 1.8 KB
/
test_features_key.py
File metadata and controls
55 lines (41 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# encoding: utf-8
# pylint: skip-file
"""
This file contains tests for the madmom.features.key module.
"""
from __future__ import absolute_import, division, print_function
import unittest
from os.path import join as pj
from madmom.features import Activations
from madmom.features.key import *
from . import AUDIO_PATH, ACTIVATIONS_PATH
sample_file = pj(AUDIO_PATH, 'sample.wav')
sample2_file = pj(AUDIO_PATH, 'sample2.wav')
sample_key_act = Activations(pj(ACTIVATIONS_PATH, 'sample.key_cnn.npz'))
sample2_key_act = Activations(pj(ACTIVATIONS_PATH, 'sample2.key_cnn.npz'))
class TestHelperFunctions(unittest.TestCase):
def test_key_prediction_to_label_function(self):
self.assertEqual(key_prediction_to_label(sample_key_act), 'Ab major')
self.assertEqual(
key_prediction_to_label(sample_key_act[0]), 'Ab major')
self.assertEqual(
key_prediction_to_label(np.roll(sample_key_act[0], 1)), 'A minor')
self.assertEqual(
key_prediction_to_label(np.roll(sample_key_act[0], -3)), 'F major')
self.assertEqual(key_prediction_to_label(sample2_key_act), 'A minor')
self.assertEqual(
key_prediction_to_label(sample2_key_act[0]), 'A minor')
self.assertEqual(
key_prediction_to_label(np.roll(sample2_key_act[0], 1)),
'Bb minor')
self.assertEqual(
key_prediction_to_label(np.roll(sample2_key_act[0], -3)),
'F# major')
class TestCNNKeyRecognitionProcessorClass(unittest.TestCase):
def setUp(self):
self.processor = CNNKeyRecognitionProcessor()
def test_process(self):
act = self.processor(sample_file)
self.assertTrue(np.allclose(act, sample_key_act))
act = self.processor(sample2_file)
self.assertTrue(np.allclose(act, sample2_key_act))