• Stars
    star
    269
  • Rank 152,662 (Top 4 %)
  • Language
    Python
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A multi-channel neural network audio classifier using Keras

DOI

Panotti: A Convolutional Neural Network classifier for multichannel audio waveforms

Panotti image

(Image of large-eared Panotti people, Wikipedia)

This is a version of the audio-classifier-keras-cnn repo (which is a hack of @keunwoochoi's compact_cnn code). Difference with Panotti is, it has been generalized beyond mono audio, to include stereo or even more "channels." And it's undergone many refinements.

NOTE: The majority of issues people seem to have in using this utility, stem from inconsistencies in their audio datasets. This is to the point where I hesitate to delve into such reports. I suggest trying the binaural audio example and see if your same problems arise. -SH

Installation

UPDATE June 9, 2020: There is an updated version of Panotti that works with TensorFlow 2, currently in the panotti branch called 'tf2'. I'm not ready to merge that branch with master until Vibrary is also updated for TF2.

Preface: Requirements

Probably Mac OS X or Linux. (Windows users: I have no experience to offer you.) Not everything is required, here's a overview:

  • Required:
    • Python 3.5
    • numpy
    • keras
    • tensorflow
    • librosa
    • matplotlib
    • h5py
  • Optional:
    • sox ("Sound eXchange": command-line utility for examples/binaural. Install via "apt-get install sox")
    • pygame (for exampes/headgames.py)
    • For sorting-hat: flask, kivy kivy-garden

...the requirements.txt file method is going to try to install both required and optional packages.

Installation:

git clone https://github.com/drscotthawley/panotti.git

cd panotti

pip install -r requirements.txt

Demo

I'm not shipping this with any audio but you can generate some for the 'fake binaural' example (requires sox):

cd examples
./binaural_setup.sh
cd binaural
../../preprocess_data.py --dur=2 --clean
../../train_network.py

Quick Start

  • Make a folder called Samples/ and inside it create sub-folders with the names of each category you want to train on. Place your audio files in these sub-folders accordingly.
  • run python preprocess_data.py
  • run python train_network.py
  • run python eval_network.py - This applies the trained network to the testing dataset and gives you accuracy reports.

Data Preparation

Data organization:

Sound files should go into a directory called Samples/ that is local off wherever the scripts are being run. Within Samples, you should have subdirectories which divide up the various classes.

Example: for the IDMT-SMT-Audio-Effects database, using their monophonic guitar audio clips...

$ ls -F Samples/
Chorus/  Distortion/  EQ/  FeedbackDelay/  Flanger/   NoFX/  Overdrive/  Phaser/  Reverb/  SlapbackDelay/
Tremolo/  Vibrato/
$

(Within each subdirectory of Samples, there are loads of .wav or .mp3 files that correspond to each of those classes.)

"Is there any sample data that comes with this repo?" Not the data itself, but check out the examples/ directory. ;-)

Data augmentation & preprocessing:

(Optional) Augmentation:

The "augmentation" will vary the speed, pitch, dynamics, etc. of the sound files ("data") to try to "bootstrap" some extra data with which to train. If you want to augment, then you'll run it as

$ python augment_data.py <N> Samples/*/*

where N is how many augmented copies of each file you want it to create. It will place all of these in the Samples/ directory with some kind of "_augX" appended to the filename (where X just counts the number of the augmented data files). For augmentation it's assumed that all data files have the same length & sample rate.

(Required) Preprocessing:

When you preprocess, the data-loading will go much faster (e.g., 100 times faster) the next time you try to train the network. So, preprocess.

Preprocessing will pad the files with silence to fit the length to the length of the longest file and the number of channels to the file with the most channels. It will then generate mel-spectrograms of all data files, and create a "new version" of Samples/ called Preproc/.

It will do an 80-20 split of the dataset, so within Preproc/ will be the subdirectories Train/ and Test/. These will have the same subdirectory names as Samples/, but all the .wav and .mp3 files will have ".npy" on the end now. Datafiles will be randomly assigned to Train/ or Test/, and there they shall remain.

To do the preprocessing you just run

$ python preprocess_data.py

Training & Evaluating the Network

$ python train_network.py That's all you need. (I should add command-line arguments to adjust the layer size and number of layers...later.)

It will perform an 80-20 split of training vs. testing data, and give you some validation scores along the way.

It's set to run for 2000 epochs, feel free to shorten that or just ^C out at some point. It automatically does checkpointing by saving(/loading) the network weights via a new file weights.hdf5, so you can interrupt & resume the training if you need to.

After training, more diagnostics -- ROC curves, AUC -- can be obtained by running

$ python eval_network.py

(Changing the batch_size variable between training and evaluation may not be a good idea. It will probably screw up the Batch Normalization...but maybe you'll get luck.)

Results

On the IDMT Audio Effects Database using the 20,000 monophonic guitar samples across 12 effects classes, this code achieved 99.7% accuracy and an AUC of 0.9999. Specifically, 11 mistakes were made out of about 4000 testing examples; 6 of those were for the 'Phaser' effect, 3 were for EQ, a couple elsewhere, and most of the classes had zero mistakes. (No augmentation was used.)

This accuracy is comparable to the original 2010 study by Stein et al., who used a Support Vector Machine.

This was achieved by running for 10 hours on our workstation with an NVIDIA GTX1080 GPU.

Extra Tricks

  • We have multi-GPU training. The saving & loading means we get warning messages from Keras. Ignore those. It's because if we compile both the parallel model and its serial counterpart, it breaks things. So we leave the serial one uncompiled and that's the one we have to save. I regard this problem as a 'bug' in the Keras multi-gpu protocols.
  • Speaking of saving & loading, we encode the names of the output classes in the weights.hdf5 file using a HDF5 attribute 'class_names'.

-- [@drscotthawley](https://drscotthawley.github.io)

More Repositories

1

ml-audio-start

Suggestions for those interested in developing audio applications of machine learning
171
star
2

audio-classifier-keras-cnn

Audio Classifier in Keras using Convolutional Neural Network
Python
158
star
3

signaltrain

learning audio effects with neural networks
Python
98
star
4

aeiou

(ML) audio engineering i/o utils
Jupyter Notebook
52
star
5

DLAIE

Materials for Hawley's Deep Learning & AI Ethics course
Jupyter Notebook
34
star
6

fad_pytorch

Frechet Audio Distance evaluation in PyTorch
Python
33
star
7

audio-algebra

alchemy with embeddings
Jupyter Notebook
33
star
8

SHAART

SHAART is a Python-based audio analysis toolkit, for educational purposes
Python
27
star
9

vibrary

Vibrary is a GUI client for a user-trainable neural network tool to help producers find audio files on their hard drives
C++
17
star
10

midi-player

Python launcher of animated MIDI player by @cifkao & @magenta
Python
16
star
11

vicregaddon

A lightweight and modular parallel PyTorch implementation of VICReg (intended for audio)
Python
13
star
12

blog_fastpages

Scott H. Hawley's Blog
Jupyter Notebook
10
star
13

PolarPatternPlotter

iOS app for measuring sound directivity of loudspeakers and microphones
Swift
10
star
14

SoundFieldsForever

App Suite for Visualizing Sound in 3D
C#
7
star
15

devblog3

another dev blog attempt
Jupyter Notebook
6
star
16

fastproaudio

End-to-end audio deep learning with fastai
Jupyter Notebook
5
star
17

FaceOSC-iOS

Port to iOS of Christopher Baker's FaceOSC for Kyle McDonald's ofxFaceTracker, with output set to be compatible with Rebecca Fiebrink's Wekinator
Objective-C++
5
star
18

espiownage

Ownage of ESPI image inference. (Pronounced like "espionage" but with a little "own" in the middle.)
Jupyter Notebook
4
star
19

NASH_time_align

Learning to do Time Alignment. Built within the fastproaudio repo, cf. https://drscotthawley.github.io/fastproaudio/time_align.html
Jupyter Notebook
4
star
20

botograder

An autograder for jupyter notebooks
Python
3
star
21

image-capture-opencv

Python utility for image capture, frame subtraction, (e.g. for ESPI)
Python
3
star
22

prefigure

Run configuration management utils: combines configparser, argparse, and wandb.API
Python
3
star
23

DataLoader

FanFic account of DJ DataLoader
2
star
24

SPNet

Object detection for ESPI images of oscillating steelpan drums
Python
2
star
25

room-shape

'Deep' neural network learns (boxy) room shape given mode frequencies, or vice versa
Python
2
star
26

talks

talks I've given
Jupyter Notebook
2
star
27

blog

my new blog site
Jupyter Notebook
2
star
28

TTTT

Trying To Teach Transformers - dump/playground for code
Jupyter Notebook
1
star
29

machinelearningfoundations

A series of tutorials I'm writing for myself and students
Jupyter Notebook
1
star
30

blog_quarto

Quarto version of former fastpages blog
Jupyter Notebook
1
star
31

add-menu-popover-demo

Swift: Example of a popover window with a navigation controller and multiple pages for user selection
Swift
1
star
32

mrspuff

A library for Deep Learning education. (deep learning <=> having a school at the bottom of the ocean)
Jupyter Notebook
1
star
33

oplas

Official repository for "Operational Latent Spaces"
Jupyter Notebook
1
star