<commit_before># audio-classifier-keras-cnn
Audio Classifier in Keras using Convolutional Neural Network

*ok this is a public repo, but it's not ready for public distribution.  Just letting a few students & colleagues know about it for now.
Wrote the main code Monday night, got the results Tuesday morning, added the augmentation Wednesday night (for future use)...now posting this repo on Thursday.*

**Credits:** This is an amalgamation of the [Keras MNIST CNN example](https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py) and [@keunwoochoi](https://github.com/keunwoochoi)'s [CNN Music Tagger](https://github.com/keunwoochoi/music-auto_tagging-keras) -- I would truly say my code is just a "dumbed-down rip-off" of Choi's work (just not his exact code because it was too clever for me).  In particular, like in Choi's work, it uses mel-spectrograms as inputs, and a multi-layer CNN with Batch Normalization and ELU activations. (Although ReLU seems to work just as well as ELU on the data I've tried so far.)

*(Regarding Batch Normalization: Changing the `batch_size` variable between training and evaluation may not be a good idea.)*


## Dependencies
* Python
* numpy
* keras
* theano or tensorflow (as backends)
* librosa

## Quick Start
* In `Samples/`, create  subdirectories for each class and put your audio files in them.
* run `python preprocess_data.py`
* run `python train_network.py`
* optional: run `python eval_network.py`


## 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](https://www.idmt.fraunhofer.de/en/business_units/m2d/smt/audio_effects.html), using their monophonic guitar audio clips...

    $ ls -F Samples/
    Chorus/  Distortion/  EQ/  FeedbackDelay/  Flanger/   NoFX/  Overdrive/  Phaser/  Reverb/  SlapbackDelay/<commit_msg>just added a sentence about difference from Choi's code.<commit_after># audio-classifier-keras-cnn
Audio Classifier in Keras using Convolutional Neural Network

*ok this is a public repo, but it's not ready for public distribution.  Just letting a few students & colleagues know about it for now.
Wrote the main code Monday night, got the results Tuesday morning, added the augmentation Wednesday night (for future use)...now posting this repo on Thursday.*

**Credits:** This is an amalgamation of the [Keras MNIST CNN example](https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py) and [@keunwoochoi](https://github.com/keunwoochoi)'s [CNN Music Tagger](https://github.com/keunwoochoi/music-auto_tagging-keras) -- I would truly say my code is just a "dumbed-down rip-off" of Choi's work (just not his exact code because it was too clever for me).  In particular, like in Choi's work, it uses mel-spectrograms as inputs, and a multi-layer CNN with Batch Normalization and ELU activations. (Although ReLU seems to work just as well as ELU on the data I've tried so far.) Unlike Choi's work, the network uses the same kernel size for all layers (that's not smart, but it still works), the melgram-shape is not hardcoded and adapts to whatever the shape is, and I threw in an optional thing for data augmentation which may come in handy later.

*(Regarding Batch Normalization: Changing the `batch_size` variable between training and evaluation may not be a good idea.)*


## Dependencies
* Python
* numpy
* keras
* theano or tensorflow (as backends)
* librosa

## Quick Start
* In `Samples/`, create  subdirectories for each class and put your audio files in them.
* run `python preprocess_data.py`
* run `python train_network.py`
* optional: run `python eval_network.py`


## 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](https://www.idmt.fraunhofer.de/en/business_units/m2d/smt/audio_effects.html), using their monophonic guitar audio clips...

    $ ls -F Samples/
    Chorus/  Distortion/  EQ/  FeedbackDelay/  Flanger/   NoFX/  Overdrive/  Phaser/  Reverb/  SlapbackDelay/
{'fraction_non_alphanumeric': 0.08314193844740468, 'fraction_numerical': 0.00045934772622875517, 'mean_word_length': 4.389851485148514, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4950755', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1238, 'n_words': 555}