forked from CPJKU/madmom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CNNChordRecognition
executable file
·89 lines (65 loc) · 2.89 KB
/
CNNChordRecognition
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
# encoding: utf-8
"""
Chord Recognizer based on features extracted by a Convolutional Neural Network.
"""
from __future__ import absolute_import, division, print_function
import argparse
from madmom.features import (ActivationsProcessor, CNNChordFeatureProcessor,
CRFChordRecognitionProcessor)
from madmom.io import write_chords
from madmom.processors import IOProcessor, io_arguments
def main():
"""CNNChordRecognition"""
p = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter, description='''
The CNNChordRecognition program recognises major and minor chords in an
audio file by first extracting learned features using a Convolutional
Neural network, and then decoding the most likely chord sequence using a
linear-chain Conditional Random Field, as described in
Filip Korzeniowski and Gerhard Widmer,
"A Fully Convolutional Deep Auditory Model for Musical Chord Recognition",
Proceedings of IEEE International Workshop on Machine Learning for Signal
Processing (MLSP), 2016.
This method is computationally more expensive than the one implemented
in DCChordRecognition but gives better results.
This program can be run in 'single' file mode to process a single audio
file and write the recognised chords to STDOUT or the given output file.
$ CNNChordRecognition single INFILE [-o OUTFILE]
The program can also be run in 'batch' mode to process multiple audio
files and save the chords to files with the given suffix.
$ CNNChordRecognition batch [-o OUTPUT_DIR] [-s OUTPUT_SUFFIX] FILES
If no output directory is given, the program writes the files with the
extracted chords to the same location as the audio files.
The 'pickle' mode can be used to store the used parameters to be able to
exactly reproduce experiments.
'''
)
# version
p.add_argument('--version', action='version',
version='CNNChordRecognition.2016')
io_arguments(p, output_suffix='.chords.txt')
ActivationsProcessor.add_arguments(p)
args = p.parse_args()
# set immutable arguments
args.fps = 10
if args.verbose:
print(args)
# input processor
if args.load:
# load activations (features) from a file
in_processor = ActivationsProcessor(mode='r', **vars(args))
else:
in_processor = CNNChordFeatureProcessor(**vars(args))
# output processor
if args.save:
# save activations (features) to a file
out_processor = ActivationsProcessor(mode='w', **vars(args))
else:
# load conditional random field
chord_processor = CRFChordRecognitionProcessor(**vars(args))
out_processor = [chord_processor, write_chords]
processor = IOProcessor(in_processor, out_processor)
args.func(processor, **vars(args))
if __name__ == '__main__':
main()