Coder Social home page Coder Social logo

radkoff / drum_sound_classifier Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 3.0 149 KB

A python module for making pandas datasets out of drum libraries, and training drum type classification models using a few different methods.

License: MIT License

Python 100.00%

drum_sound_classifier's Introduction

Drum Sound Classification

A python module for making pandas datasets out of drum libraries, and training drum type classification models using a few different methods. Read my accompanying blog post.

Waveforms and spectrograms of a few random snare sounds

Set up

  1. Install requirements with pip. From this cloned repository it should be enough to do pip install ., but using a virtual environment is encouraged.
  2. Get drum sounds. I recommend r/drumkits
  3. Run something like python drum_sound_classifier/preprocess.py --drum_lib_path /path/to/drums. This will recursively search, so nested directories are fine. It will safely skip any non-audio files. Run python preprocess.py --help for options.
    • If you would like to inspect the resulting dataset yourself, this will create a pickled pandas dataframe data/interim/dataset.pkl

Training

To train a random forrest classifier on drum descriptors, run:

python drum_sound_classifier/models/train_sklearn.py --inputs descriptors --model random_forest

You may want to add --no_extract_spectrograms if you don't plan on using a GPU to train a CNN model. Otherwise, spectrogram data will be pre-extracted which takes up disk space.

To train a CNN-based model (a GPU is essential), run:

python drum_sound_classifier/models/train_cnn.py

And finally, assuming you have a CNN model trained, to try a SVC over CNN embeddings run:

python drum_sound_classifier/models/train_sklearn.py --inputs cnn_embeddings --model svc

Run any of the above with --help for options.

Inference

I have yet to add support for inference using sklearn-derived models (pull requests welcome!), but to infer with CNN models see inference.py

drum_sound_classifier's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

drum_sound_classifier's Issues

train_cnn does not work with GPU

ERROR:ignite.engine.engine.Engine:Current run is terminating due to exception: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
ERROR:ignite.engine.engine.Engine:Engine run is terminating due to exception: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
Traceback (most recent call last):
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\ignite\engine\engine.py", line 775, in _internal_run
self._handle_exception(e)
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\ignite\engine\engine.py", line 469, in _handle_exception
raise e
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\ignite\engine\engine.py", line 745, in _internal_run
time_taken = self._run_once_on_dataset()
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\ignite\engine\engine.py", line 850, in _run_once_on_dataset
self._handle_exception(e)
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\ignite\engine\engine.py", line 469, in _handle_exception
raise e
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\ignite\engine\engine.py", line 833, in _run_once_on_dataset
self.state.output = self.process_function(self, self.state.batch)
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\ignite\engine_init
.py", line 103, in _update
y_pred = model(x)
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "C:/Work/drum_sound_classifier/drum_sound_classifier/models/train_cnn.py", line 44, in forward
self.conv1_batch(self.conv1(tensor)),
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\torch\nn\modules\module.py", line 1051, in _call_impl
return forward_call(*input, **kwargs)
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\torch\nn\modules\conv.py", line 443, in forward
return self._conv_forward(input, self.weight, self.bias)
File "C:\Work\drum_sound_classifier\venv\lib\site-packages\torch\nn\modules\conv.py", line 439, in _conv_forward
return F.conv2d(input, weight, bias, self.stride,
RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.