How to do it...

The strategy discussed above is coded as follows (the code file is available as Genre_classification.ipynb in GitHub):

  1. Download the dataset and import the relevant packages:
import sys, re, numpy as np, pandas as pd, music21, IPython, pickle, librosa, librosa.dsiplay, osfrom glob import globfrom tqdm import tqdmfrom keras.utils import np_utils
  1. Loop through the audio files to extract the  mel spectrogram input features of the input audio, and store the output genre for the audio input:
song_specs=[]genres = []for genre in os.listdir('...'): # Path to genres folder  song_folder = '...' # Path to songs folder  for song in os.listdir(song_folder):    if song.endswith('.au'): signal, sr = librosa.load(os.path.join(song_folder, song), ...

Get Neural Networks with Keras Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.