TechieYan Technologies

Identifying Music genre


How many times we have wondered, what might have been a songs genre, sometimes it might be easy and sometimes it might make our brains go wild, so this is it, this program allows us to predict the genre of the music using Transfer learning. The flow is as follows first we load the music file, split the songs into chunks, then load the model using load model (), using the loaded model, predict on the music which you ahve loaded earlier and since the output will be in the form of array, we use argmax () to extract the highest probability of the music genre the model has predicted.

Code Description & Execution

Algorithm Description

So, the approach we have taken to run/execute this project is by using Transfer Learning, so basically transfer learning is a method where we train our dataset with a model which was already trained on such type of problem that we are working on i.e. Since we are dealing with a classification problem i.e., classifying which genre the music belongs to so we use a specific transfer learning algorithm which is made of classification problem. So, the model we are using in this project is VGG16. VGG16 is basically a 16-layer convolutional neural network which was trained on image net datset which consists of 14 million images, with around 1000 classes. VGG16 is most preferred classification model if we wanted to use transfer learning in our project. This model along with such good accuracy and performance, it also comes with some disadvantages such as exploding gradient descent problem due to more than 100 million parameters for training and due to the size of the model i.e., 528 MB, although it might be a very small size but this will take a lot of time to run and even download in many systems.


How to Execute?

Make sure you have checked the add to path tick boxes while installing python, anaconda. 

Refer to this link, if you are just starting and want to know how to install anaconda.

 If you already have anaconda and want to check on how to create anaconda environment, refer to this article set up jupyter notebook.

You can skip the article if you have knowledge of installing anaconda, setting up environment and installing requirements.txt

Install the prerequisites/software’s required to execute the code from reading the above blog which is provided in the link above.

  1. Press windows key and type in anaconda prompt a terminal opens up.
  2. Go to the directory where your requirement.txt file is present, not just requirement.txt, if you want to execute any .py or .ipynb files, you need to go to that specific folder or path, where they are saved.
  3. <>. E.g., If my file is in d drive, then
  4. Type d:


  5. cd d:\License-Plate-Recognition-main    #CHANGE PATH AS PER YOUR PROJECT, THIS IS JUST AN EXAMPLE.

identifying music

6. If your project is in c drive, you can ignore step 4 and go with step

E.g., cd C:\Users\Hi\License-Plate-Recognition-main


8. Run pip install -r requirements.txt or conda install requirements.txt (Requirements.txt is a text file consisting of all the necessary libraries required for executing this python file. If it gives any error while installing libraries, you might need to install them individually.), example: pip install “module_name” i.e., pip install pandas

identifyng music

  9. To run .py file make sure you are in the anaconda terminal with the anaconda path being set as your executable file/folder is being saved. Then type python main.pyin the terminal, before running open the and make sure to change the path of the dataset.

 10. If you would like to run .ipynb file, Please follow the link to setup and open jupyter notebook, You will be redirected to the local server there you can select which ever .ipynb file you’d like to run and click on it and execute each cell one by one by pressing shift+enter.

 11. Run classification_cnn_vgg.ipynb.ipynb run the final code, and make sure to change the path of the model and image folders.


     Make sure to change the path of the dataset in the code

Data Description

Dataset consists of 9 different classes of music genres each has around 500 audio files. Below is the link which helps to download the dataset.


Final Results

Identifying Music genre graph
Identifying Music genre

Issues you may face while executing the code

  1. We might face an issue while installing specific libraries.
  2. Make sure you have the latest version of python, since sometimes it might cause version mismatch.
  3. Adding path to environment variables in order to run python files and anaconda environment in code editor, specifically in visual studio code.
  4. Refer to the Below link to get more details on installing python and anaconda and how to configure it.


Click Here To Download This Code And Associated File.

+91 7075575787