<jupyter_start><jupyter_text>Music Genre Recognition  1. Preparing dataset<jupyter_code>def load(filepath):

    filename = os.path.basename(filepath)

    if 'features' in filename:
        return pd.read_csv(filepath, index_col=0, header=[0, 1, 2])

    if 'echonest' in filename:
        return pd.read_csv(filepath, index_col=0, header=[0, 1, 2])

    if 'genres' in filename:
        return pd.read_csv(filepath, index_col=0)

    if 'tracks' in filename:
        tracks = pd.read_csv(filepath, index_col=0, header=[0, 1])

        COLUMNS = [('track', 'tags'), ('album', 'tags'), ('artist', 'tags'),
                   ('track', 'genres'), ('track', 'genres_all')]
        
        for column in tqdm(COLUMNS, desc='Loading tracks...'):
            tracks[column] = tracks[column].map(ast.literal_eval)

        COLUMNS = [('track', 'date_created'), ('track', 'date_recorded'),
                   ('album', 'date_created'), ('album', 'date_released'),
                   ('artist', 'date_created'), ('artist', 'active_year_begin'),
                   ('artist', 'active_year_end')]
        
        for column in tqdm(COLUMNS, desc='Loading tracks...'):
            tracks[column] = pd.to_datetime(tracks[column])

        SUBSETS = ('small', 'medium', 'large')
        tracks['set', 'subset'] = tracks['set', 'subset'].astype(
                'category', categories=SUBSETS, ordered=True)

        COLUMNS = [('track', 'license'), ('artist', 'bio'),
                   ('album', 'type'), ('album', 'information')]
        for column in COLUMNS:
            tracks[column] = tracks[column].astype('category')

        return tracks
%%time
metadata_path = 'C:/Users/Febrin/Desktop/fma_metadata/tracks.csv'
tracks_metadata = load(metadata_path) 
tracks_metadata['track'].head()
tracks_metadata['album'].head()
tracks_metadata['artist'].head()
tracks_metadata['set'].head()
audio_path = 'C:/Users/Febrin/Desktop/fma_small'
audio_folders = os.listdir(audio_path)[:-2]
AUDIO_PATHS = []

for folder in audio_folders:
    audio = os.listdir(audio_path +'/'+ folder)
    print(audio)
    break<jupyter_output>['000002.mp3', '000005.mp3', '000010.mp3', '000140.mp3', '000141.mp3', '000148.mp3', '000182.mp3', '000190.mp3', '000193.mp3', '000194.mp3', '000197.mp3', '000200.mp3', '000203.mp3', '000204.mp3', '000207.mp3', '000210.mp3', '000211.mp3', '000212.mp3', '000213.mp3', '000255.mp3', '000256.mp3', '000368.mp3', '000424.mp3', '000459.mp3', '000534.mp3', '000540.mp3', '000546.mp3', '000574.mp3', '000602.mp3', '000615.mp3', '000620.mp3', '000621.mp3', '000625.mp3', '000666.mp3', '000667.mp3', '000676.mp3', '000690.mp3', '000694.mp3', '000695.mp3', '000704.mp3', '000705.mp3', '000706.mp3', '000707.mp3', '000708.mp3', '000709.mp3', '000714.mp3', '000715.mp3', '000716.mp3', '000718.mp3', '000777.mp3', '000814.mp3', '000821.mp3', '000822.mp3', '000825.mp3', '000853.mp3', '000890.mp3', '000892.mp3', '000897.mp3', '000993.mp3', '000995.mp3', '000997.mp3', '000998.mp3']<jupyter_text>2. Converting audio data into mel-spectogram<jupyter_code>path = 'C:/Users/Febrin/Desktop/fma_small'
y, sr = librosa.load(path)
spect = librosa.feature.melspectrogram(y=y, sr=sr,n_fft=2048, hop_length=512)
spect = librosa.power_to_db(spect, ref=np.max)<jupyter_output>C:\Users\Febrin\AppData\Local\Programs\Python\Python37\lib\site-packages\librosa\core\audio.py:161: UserWarning: PySoundFile failed. Trying audioread instead.
  warnings.warn('PySoundFile failed. Trying audioread instead.')
{'fraction_non_alphanumeric': 0.19367816091954024, 'fraction_numerical': 0.1324712643678161, 'mean_word_length': 4.030346820809249, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 62, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '325343', 'license': 'MIT', 'n_tokens_mistral': 1603, 'n_tokens_neox': 1299, 'n_words': 226, 'path': 'NN-DL/TensorflowWorkshop/.ipynb_checkpoints/MusicGenreRecognition-checkpoint.ipynb', 'repo_name': 'TheFebrin/Machine-Learning', 'size': '3480'}