Coder Social home page Coder Social logo

magus4450 / musicgenreclassification Goto Github PK

View Code? Open in Web Editor NEW
13.0 1.0 1.0 46.76 MB

Music Genre Classification with all data pipeline steps

Python 0.60% Jupyter Notebook 99.40%
data-collection feature-extraction ffmpeg librosa machine-learning spotify threading youtube

musicgenreclassification's Introduction

Music Genre Classification

This is a repository for Music Genre Classification Project which includes Data Collection, Feature Extraction, Training and Deployment.

Virtual Environment

With virtual environment, you can easily install all requirements in one go. To do so, follow these steps:

  1. Create a virtual environment
    python -m venv env
  2. Activate the virtual environment
    Windows: ./env/Scripts/activate
    Linux: source env/bin/actiavte
  3. Install requirements
    pip install -r requirements.txt

1. Data Collection

Data in collected in a four step process.

  1. Song names fetched from Spotify API according to provided Genres.
  2. Youtube video URL fetched from Youtube API from the song names.
  3. Songs downloaded using those Youtube video URLs.
  4. Songs segmented into clips of specified seconds.

How to use

  1. Install required libraries
  2. Acquire required API Keys (Store all acquired Keys in SongCollection/.env)
    1. Spotify API Keys
      • Login to SpotifyDev
      • Store keys as follows in .env file
        • SPOTIFY_CLIENT_ID = Your client id
        • SPOTIFY_CLIENT_SECRET = Your client secret
    2. Youtube API Keys
      • Login to GoogleCloudConsole
      • Make a Project
      • Enable YouTubeAPI
      • In sidetabs, go to Credentials > Create API Key
      • Store keys as follows in .env file (You can use more than one. One key can be used to get URls of about 500 songs)
        • YOUTUBE_API_KEY0 = Your 1st api key
        • YOUTUBE_API_KEY1 = Your 2nd api key
        • . . .
  3. Run the program
    1. For Song name and URL

      1. Make object of APICall as
        ac = APICall(genre_list, number_of_songs, number_of_youtube_keys)
        Example:
        ac = APICall(["classical", "rock"],50, 1)
      2. Get song names
        ac.generate_song_list()
      3. Get song URLs
        ac.generate_song_url()
      4. Access song name and urls from text files
        song_name ,song_url = ac.get_song_name_url()
    2. To Download and Segment

      1. Make object of SongDownloader as
        sc = SongDownloader(n_threads, segment_duration)
        Example:
        sd = SongDownloader(10, 30)
      2. Download and segment
        sd.download_song(song_name, song_url)

2. Feature Extraction

Feature Extraction makes use of Librosa to extract a total of 38 features from both frequenct domain and time domain. Extracted features are Mean and Standard Deviations of:

  • Amplitude Envelope
  • Root Mean Squared Energy
  • Zero Crossing Rate
  • Band Energy Ratio
  • Spectral Centroid
  • Bandwidth
  • 13 Mel Frequency Cepstral Coefficients (MFCCs)

How to use

  1. Complete How to use of Data Collection
  2. Install required libraries
  3. Run the program
    1. Make object of FeatureExtractor as
      fe = FeatureExtractor(segment_duration, n_threads) (Segment duration must be same as Data Collection)
      Example:
      fe = FeatureExtractor(30, 10)
    2. Extract features
      fe.extract_features()

3. Training

In this part, I have dome some preliminary exploratory data analysis along with visualization of different features that has been extracted .

The data was trained on different models with primary evalulation metrics being the F1 Score and Confusion Matrix. The data being highly imbalanced, balancing techniques like UnderSampling and OverSampling were used. Random Search was also employed to find best hyperparameters for the model.

The best model was a RandomForestClassifer with test F1 Score of 70%. This model was trained by dropping BER_Mean and BER_Std columns as these data had multiple discrepancies.

The model was extracted into a file by pickle to be used in deployment.


4. Deployment

In Progress


musicgenreclassification's People

Contributors

magus4450 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

duobin

musicgenreclassification's Issues

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.