### Install musicnn from source Source: https://github.com/jordipons/musicnn/blob/master/README.md Install musicnn after cloning the repository to include larger models and documentation. ```bash python setup.py install ``` -------------------------------- ### Install musicnn using pip Source: https://github.com/jordipons/musicnn/blob/master/README.md Install the musicnn library using pip for basic usage. ```bash pip install musicnn ``` -------------------------------- ### Clone musicnn repository from source Source: https://github.com/jordipons/musicnn/blob/master/README.md Clone the musicnn repository from GitHub to install with bigger models and full documentation. ```bash git clone https://github.com/jordipons/musicnn.git ``` -------------------------------- ### Matplotlib Setup for Taggram Plotting Source: https://github.com/jordipons/musicnn/blob/master/tagging_example.ipynb Imports necessary libraries and sets up Matplotlib configurations for plotting the taggram and other visualizations. Adjust figure size and font size as needed. ```python %matplotlib inline import numpy as np import matplotlib.pyplot as plt ``` ```python in_length = 3 # seconds by default, the model takes inputs of 3 seconds with no overlap plt.rcParams["figure.figsize"] = (10,8) # set size of the figures fontsize = 12 # set figures font size ``` -------------------------------- ### Extract Music Features using MTT_musicnn Model Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Use the musicnn extractor to get taggrams, tags, and intermediate features from an audio file. This requires the 'MTT_musicnn' model and feature extraction to be enabled. ```python from musicnn.extractor import extractor taggram, tags, features = extractor(file_name, model='MTT_musicnn', extract_features=True) ``` -------------------------------- ### Extract Taggram for Temporal Tag Evolution Source: https://github.com/jordipons/musicnn/blob/master/tagging_example.ipynb This snippet extracts the taggram, which represents the temporal evolution of tag likelihoods for a given audio file. Set extract_features to False to get the taggram. ```python from musicnn.extractor import extractor taggram, tags = extractor(file_name, model='MTT_musicnn', extract_features=False) ``` -------------------------------- ### Print top tags from command-line Source: https://github.com/jordipons/musicnn/blob/master/README.md Use the musicnn.tagger module from the command-line to print the top N tags for an audio file. ```bash python -m musicnn.tagger file_name.ogg --print ``` -------------------------------- ### Save and print top tags with custom parameters from command-line Source: https://github.com/jordipons/musicnn/blob/master/README.md Save top N tags to a file and print them to the console, using custom model and processing parameters. ```bash python -m musicnn.tagger file_name.mp3 --model 'MTT_musicnn' --topN 10 --length 3 --overlap 1 --print --save out.tags ``` -------------------------------- ### Print top tags with custom model and parameters from command-line Source: https://github.com/jordipons/musicnn/blob/master/README.md Print top N tags from the command-line using a specified model, topN, length, and overlap. ```bash python -m musicnn.tagger file_name.au --model 'MSD_musicnn' --topN 3 --length 3 --overlap 1.5 --print ``` -------------------------------- ### Tag Music File with Default Settings Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Predict tags for a music file using the default MTT_musicnn model and save the output. ```bash python -m musicnn.tagger file_name --model 'MTT_musicnn' --topN 3 --length 3 --overlap 3 --print --save file.tags ``` -------------------------------- ### Tag Music File and Print Tags Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Predict and print the tags for a music file directly to the console. ```bash python -m musicnn.tagger music.mp3 --print ``` -------------------------------- ### Predict top tags with default model in Python Source: https://github.com/jordipons/musicnn/blob/master/README.md Predict top tags for an audio file using the default model settings. ```python top_tags('./audio/TRWJAZW128F42760DD_test.mp3') ``` -------------------------------- ### Tag Music File with Specific Model Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Tag a music file using the MSD_musicnn model. ```bash python -m musicnn.tagger music.mp3 --model MSD_musicnn ``` -------------------------------- ### Specify Audio File for Feature Extraction Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Define the path to the audio file you want to process. Ensure the file exists at the specified location. ```python file_name = './audio/joram-moments_of_clarity-08-solipsism-59-88.mp3' ``` -------------------------------- ### Save top tags to a file from command-line Source: https://github.com/jordipons/musicnn/blob/master/README.md Save the predicted top N tags to a specified output file using the command-line interface. ```bash python -m musicnn.tagger file_name.wav --save out.tags ``` -------------------------------- ### Tag Music File with Custom TopN Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Extract a custom number of top tags (e.g., 10) for a music file. ```bash python -m musicnn.tagger music.mp3 --topN 10 ``` -------------------------------- ### Specify Audio File Path Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Defines the path to the audio file for feature extraction. ```python file_name = './audio/TRWJAZW128F42760DD_test.mp3' ``` -------------------------------- ### List Available Intermediate Features Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Inspect the keys of the 'features' dictionary to see all available intermediate representations extracted from the musicnn model. ```python list(features.keys()) ``` -------------------------------- ### Tag Music File and Save Tags Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Predict tags for a music file and save them to a specified CSV file. ```bash python -m musicnn.tagger music.mp3 --save out.tags ``` -------------------------------- ### Visualize Front-end Features Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Displays the concatenated 'frontend_features' using the depict_features function. Sets aspect ratio to 'equal'. ```python gs = gridspec.GridSpec(1, 1) # create a figure having 1 rows and 3 cols. depict_features(features=frontend_features, coordinates=gs[0, 0], title='front-end features', aspect='equal') plt.show() ``` -------------------------------- ### Tag Music File with Custom Length Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Process a music file with a custom spectrogram patch length (e.g., 3.1 seconds). ```bash python -m musicnn.tagger music.mp3 -len 3.1 ``` -------------------------------- ### Predict top tags for an audio file in Python Source: https://github.com/jordipons/musicnn/blob/master/README.md Use the top_tags function from musicnn.tagger to estimate the top N tags for a given audio file. Specify the model and topN parameters as needed. ```python from musicnn.tagger import top_tags top_tags('./audio/joram-moments_of_clarity-08-solipsism-59-88.mp3', model='MTT_musicnn', topN=10) ``` -------------------------------- ### Visualize Output Features (Pooling and Penultimate) Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Displays 'mean_pool', 'max_pool', and 'penultimate' layer features using the depict_features function. 'mean_pool' and 'max_pool' span all rows in the grid, while 'penultimate' is in the last column of the last row. Uses tight_layout. ```python plt.rcParams["figure.figsize"] = (9,6) gs = gridspec.GridSpec(4, 3) # create a figure having 1 rows and 3 cols. depict_features(features=features['mean_pool'], coordinates=gs[:, 0], title='mean-pool features') depict_features(features=features['max_pool'], coordinates=gs[:, 1], title='max-pool features') depict_features(features=features['penultimate'], coordinates=gs[3, 2], title='penultimate-layer features') plt.tight_layout() plt.show() ``` -------------------------------- ### Tag Music File with Custom Overlap Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Tag a music file with a custom overlap amount for spectrogram patches (e.g., 1.0 second). ```bash python -m musicnn.tagger music.mp3 -ov 1.0 ``` -------------------------------- ### Visualize Audio Taggram Data Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb This snippet visualizes audio taggram data using Matplotlib. It sets y-axis labels for tags and x-axis labels for time, then displays the plot. Ensure Matplotlib and NumPy are imported. ```python # y-axis y_pos = np.arange(len(tags)) ax.set_yticks(y_pos) ax.set_yticklabels(tags, fontsize=fontsize-1) # x-axis x_pos = np.arange(taggram.shape[0]) x_label = np.arange(in_length/2, in_length*taggram.shape[0], 3) ax.set_xticks(x_pos) ax.set_xticklabels(x_label, fontsize=fontsize) plt.show() ``` -------------------------------- ### Visualize pool5 Features Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Visualizes all feature maps from the 'pool5' layer using a 1x1 grid. This is used when the feature maps are 2D and all need to be displayed. ```python # visualize pool5 features! gs = gridspec.GridSpec(1, 1) # create a figure having 1 rows and 1 cols. depict_features(features=features['pool5'], coordinates=gs[0, 0], title='pool5 features', xlabel=False) plt.tight_layout() plt.show() ``` -------------------------------- ### Visualize Temporal Features Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Displays the 'temporal' features using the depict_features function. Sets aspect ratio to 'equal'. ```python gs = gridspec.GridSpec(1, 1) # create a figure having 1 rows and 3 cols. depict_features(features=features['temporal'], coordinates=gs[0, 0], title='temporal features', aspect='equal') plt.show() ``` -------------------------------- ### Visualize Timbral Features Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Displays the 'timbral' features using the depict_features function. Sets aspect ratio to 'auto'. ```python gs = gridspec.GridSpec(1, 1) # create a figure having 1 rows and 1 cols. depict_features(features=features['timbral'], coordinates=gs[0, 0], title='timbral features', aspect='auto') plt.show() ``` -------------------------------- ### Plot Song-Level Tag Likelihood Source: https://github.com/jordipons/musicnn/blob/master/tagging_example.ipynb Visualizes the song-level tag likelihoods as a bar chart. The y-axis shows the likelihood (0 to 1), and the x-axis displays the tags, rotated for readability. ```python fig, ax = plt.subplots() # title ax.title.set_text('Tags likelihood (mean of the taggram)') ax.title.set_fontsize(fontsize) # y-axis title ax.set_ylabel('(likelihood)', fontsize=fontsize) # y-axis ax.set_ylim((0, 1)) ax.tick_params(axis="y", labelsize=fontsize) # x-axis ax.tick_params(axis="x", labelsize=fontsize-1) pos = np.arange(len(tags)) ax.set_xticks(pos) ax.set_xticklabels(tags, rotation=90) # depict song-level tags likelihood ax.bar(pos, tags_likelihood_mean) plt.show() ``` -------------------------------- ### Visualize pool2 Features Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Visualizes 6 selected feature maps from the 'pool2' layer using a 3x2 grid. Each feature map is plotted individually with its corresponding title. ```python # visualize pool2 features! gs = gridspec.GridSpec(3, 2) # create a figure having 2 rows and 3 cols. depict_features(features=features['pool2'][:,:,10], coordinates=gs[0, 0], title='pool2: feature #10', xlabel=False) depict_features(features=features['pool2'][:,:,5], coordinates=gs[1, 0], title='pool2: feature #5', xlabel=False) depict_features(features=features['pool2'][:,:,121], coordinates=gs[2, 0], title='pool2: feature #121', xlabel=False) depict_features(features=features['pool2'][:,:,33], coordinates=gs[0, 1], title='pool2: feature #33', xlabel=False) depict_features(features=features['pool2'][:,:,59], coordinates=gs[1, 1], title='pool2: feature #59', xlabel=False) depict_features(features=features['pool2'][:,:,100], coordinates=gs[2, 1], title='pool2: feature #100', xlabel=False) plt.tight_layout() plt.show() ``` -------------------------------- ### Visualize pool3 Features Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Visualizes 6 selected feature maps from the 'pool3' layer using a 3x2 grid. Each feature map is plotted individually with its corresponding title. ```python # visualize pool3 features! gs = gridspec.GridSpec(3, 2) # create a figure having 2 rows and 3 cols. depict_features(features=features['pool3'][:,:,100], coordinates=gs[0, 0], title='pool3: feature #100', xlabel=False) depict_features(features=features['pool3'][:,:,50], coordinates=gs[1, 0], title='pool3: feature #50', xlabel=False) depict_features(features=features['pool3'][:,:,122], coordinates=gs[2, 0], title='pool3: feature #122', xlabel=False) depict_features(features=features['pool3'][:,:,83], coordinates=gs[0, 1], title='pool3: feature #83', xlabel=False) depict_features(features=features['pool3'][:,:,9], coordinates=gs[1, 1], title='pool3: feature #9', xlabel=False) depict_features(features=features['pool3'][:,:,104], coordinates=gs[2, 1], title='pool3: feature #104', xlabel=False) plt.tight_layout() plt.show() ``` -------------------------------- ### Compute Song-Level Tag Likelihood Source: https://github.com/jordipons/musicnn/blob/master/tagging_example.ipynb Calculates the average likelihood of each tag across the entire audio clip by averaging the taggram over time. This provides a song-level tag distribution. ```python tags_likelihood_mean = np.mean(taggram, axis=0) # averaging the Taggram through time ``` -------------------------------- ### Set X-axis Ticks and Labels Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Configures the x-axis ticks and labels for a plot using matplotlib. Ensure numpy and matplotlib are imported. ```python x_pos = np.arange(taggram.shape[0]) x_label = np.arange(in_length/2, in_length*taggram.shape[0], 3) ax.set_xticks(x_pos) ax.set_xticklabels(x_label, fontsize=fontsize) plt.show() ``` -------------------------------- ### Visualize Taggram Output Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Visualizes the taggram output, which represents the temporal likelihood of tags over a 3-second input. The taggram has a temporal resolution of 3 seconds. ```python in_length = 3 # seconds -- by default, the model takes inputs of 3 seconds with no overlap # depict taggram plt.rcParams["figure.figsize"] = (10,8) fontsize=12 fig, ax = plt.subplots() ax.imshow(taggram.T, interpolation=None, aspect="auto") # title ax.title.set_text('Taggram') ax.title.set_fontsize(fontsize) # x-axis title ax.set_xlabel('(seconds)', fontsize=fontsize) ``` -------------------------------- ### Extract Features with MTT_vgg Model Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Extracts music features and tags using the MTT_vgg model. Requires the 'tensorflow' and 'librosa' libraries. ```python from musicnn.extractor import extractor taggram, tags, features = extractor(file_name, model='MTT_vgg', extract_features=True) ``` -------------------------------- ### Extract taggram and tags in Python Source: https://github.com/jordipons/musicnn/blob/master/README.md Compute the taggram and associated tags for an audio file using the extractor function from musicnn.extractor. Specify the model for extraction. ```python from musicnn.extractor import extractor taggram, tags = extractor('./audio/joram-moments_of_clarity-08-solipsism-59-88.mp3', model='MTT_musicnn') ``` -------------------------------- ### Predict Top Music Tags Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Use this function to predict the top N most likely tags for a given music file using a specified model. Ensure the file path and model name are correctly provided. The `print_tags` parameter controls whether tags are displayed directly, while `save_tags` can be used to store them to a file. ```python tags = musicnn.tagger.top_tags(file_name, model='MTT_musicnn', topN=3, input_length=3, input_overlap=None, print_tags=True, save_tags=False) ``` -------------------------------- ### Predict Top 3 Music Tags Source: https://github.com/jordipons/musicnn/blob/master/tagging_example.ipynb Use this snippet to predict the top 3 most likely tags for an audio file using the MTT model. Ensure the audio file path is correct. ```python file_name = './audio/joram-moments_of_clarity-08-solipsism-59-88.mp3' ``` ```python from musicnn.tagger import top_tags tags = top_tags(file_name, model='MTT_musicnn', topN=3) ``` -------------------------------- ### Plotting the Taggram Source: https://github.com/jordipons/musicnn/blob/master/tagging_example.ipynb Visualizes the taggram, showing the temporal likelihood of different music tags. The x-axis represents time in seconds, and the y-axis lists the tags. ```python fig, ax = plt.subplots() # title ax.title.set_text('Taggram') ax.title.set_fontsize(fontsize) # x-axis title ax.set_xlabel('(seconds)', fontsize=fontsize) # y-axis y_pos = np.arange(len(tags)) ax.set_yticks(y_pos) ax.set_yticklabels(tags, fontsize=fontsize-1) # x-axis x_pos = np.arange(taggram.shape[0]) x_label = np.arange(in_length/2, in_length*taggram.shape[0], 3) ax.set_xticks(x_pos) ax.set_xticklabels(x_label, fontsize=fontsize) # depict taggram ax.imshow(taggram.T, interpolation=None, aspect="auto") plt.show() ``` -------------------------------- ### Visualize pool4 Features Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Visualizes 6 selected feature maps from the 'pool4' layer using a 3x2 grid. Each feature map is plotted individually with its corresponding title. ```python # visualize pool4 features! gs = gridspec.GridSpec(3, 2) # create a figure having 2 rows and 3 cols. depict_features(features=features['pool4'][:,:,108], coordinates=gs[0, 0], title='pool4: feature #108', xlabel=False) depict_features(features=features['pool4'][:,:,58], coordinates=gs[1, 0], title='pool4: feature #58', xlabel=False) depict_features(features=features['pool4'][:,:,21], coordinates=gs[2, 0], title='pool4: feature #21', xlabel=False) depict_features(features=features['pool4'][:,:,23], coordinates=gs[0, 1], title='pool4: feature #23', xlabel=False) depict_features(features=features['pool4'][:,:,89], coordinates=gs[1, 1], title='pool4: feature #89', xlabel=False) depict_features(features=features['pool4'][:,:,67], coordinates=gs[2, 1], title='pool4: feature #67', xlabel=False) plt.tight_layout() plt.show() ``` -------------------------------- ### Inspect Feature Tensor Shape (pool3) Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Displays the shape of the 'pool3' feature tensor. ```python features['pool3'].shape ``` -------------------------------- ### Inspect Feature Tensor Shape (pool2) Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Displays the shape of the 'pool2' feature tensor. ```python features['pool2'].shape ``` -------------------------------- ### Inspect Feature Tensor Shape (pool4) Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Displays the shape of the 'pool4' feature tensor. ```python features['pool4'].shape ``` -------------------------------- ### Visualize Taggram Output Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Displays the 'taggram' output, representing tag likelihoods over time. Configures plot size, aspect ratio, and labels for clarity. Requires matplotlib and numpy. ```python in_length = 3 # seconds -- by default, the model takes inputs of 3 seconds with no overlap # depict taggram plt.rcParams["figure.figsize"] = (10,8) fontsize=12 fig, ax = plt.subplots() ax.imshow(taggram.T, interpolation=None, aspect="auto") # title ax.title.set_text('Taggram') ax.title.set_fontsize(fontsize) # x-axis title ax.set_xlabel('(seconds)', fontsize=fontsize) # y-axis y_pos = np.arange(len(tags)) ax.set_yticks(y_pos) ax.set_yticklabels(tags, fontsize=fontsize-1) ``` -------------------------------- ### musicnn.tagger.top_tags Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Predicts the top N tags for a given music file using a specified model. It allows customization of input length, overlap, and output options. ```APIDOC ## musicnn.tagger.top_tags ### Description Predicts the `topN` tags of the music-clip in `file_name` with the selected `model`. This function can optionally print or save the predicted tags. ### Method ```python musicnn.tagger.top_tags( file_name: str, model: str = 'MTT_musicnn', topN: int = 3, input_length: float = 3, input_overlap: float = None, print_tags: bool = True, save_tags: bool = False ) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **file_name** (string) - Required - Path to the music file to tag. Example: './audio/TRWJAZW128F42760DD_test.mp3' - **model** (string) - Optional - Select a music audio tagging model. Options: `'MTT_musicnn'`, `'MTT_vgg'`, `'MSD_musicnn'`, `'MSD_musicnn_big'`, or `'MSD_vgg'`. Defaults to `'MTT_musicnn'`. - **topN** (integer) - Optional - Extract N most likely tags. Defaults to 3. - **input_length** (floating point number) - Optional - Length in seconds of the input spectrogram patches. Recommended value is 3. Defaults to 3. - **input_overlap** (floating point number) - Optional - Amount of overlap in seconds of the input spectrogram patches. Defaults to None. - **print_tags** (boolean) - Optional - Set to `True` for printing the tags. Defaults to `True`. - **save_tags** (string) - Optional - Path where to store/save the tags. Example: 'file_name.tags'. Defaults to `False`. ### Request Example ```python tags = musicnn.tagger.top_tags(file_name='./audio/TRWJAZW128F42760DD_test.mp3', model='MTT_musicnn', topN=3, input_length=3, input_overlap=1.0, print_tags=True, save_tags=False) ``` ### Response #### Success Response - **tags** (list) - `topN` most likely tags of the music-clip. Example: `['synth', 'techno']` #### Response Example ```json { "tags": ["synth", "techno"] } ``` ``` -------------------------------- ### Visualize Pool1 Features Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Visualizes selected feature maps from the 'pool1' layer of the MTT_vgg model using the depict_features function. Requires matplotlib. ```python # visualize pool1 features! gs = gridspec.GridSpec(3, 2) # create a figure having 2 rows and 3 cols. depict_features(features=features['pool1'][:,:,0], coordinates=gs[0, 0], title='pool1: feature #0', xlabel=False) depict_features(features=features['pool1'][:,:,35], coordinates=gs[1, 0], title='pool1: feature #35', xlabel=False) depict_features(features=features['pool1'][:,:,111], coordinates=gs[2, 0], title='pool1: feature #111', xlabel=False) depict_features(features=features['pool1'][:,:,3], coordinates=gs[0, 1], title='pool1: feature #3', xlabel=False) depict_features(features=features['pool1'][:,:,39], coordinates=gs[1, 1], title='pool1: feature #39', xlabel=False) depict_features(features=features['pool1'][:,:,101], coordinates=gs[2, 1], title='pool1: feature #101', xlabel=False) plt.tight_layout() plt.show() ``` -------------------------------- ### Define Feature Depiction Function Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Defines a helper function to visualize feature tensors using matplotlib. Requires matplotlib and numpy. ```python %matplotlib inline import matplotlib.pylab as plt import matplotlib.gridspec as gridspec import numpy as np def depict_features(features, coordinates, title, aspect='auto', xlabel=True, fontsize=13): # plot features in coordinates ax = plt.subplot(coordinates) plt.imshow(features.T, interpolation=None, aspect=aspect) # set title ax.title.set_text(title + ' (' + str(features.shape[1]) + ')' ) ax.title.set_fontsize(fontsize) # y-axis ax.get_yaxis().set_visible(False) # x-axis x_label = np.arange(0, features.shape[0], features.shape[0]//5) ax.set_xticks(x_label) ax.set_xticklabels(x_label, fontsize=fontsize) if xlabel: ax.set_xlabel('(time)', fontsize=fontsize) ``` -------------------------------- ### Inspect Feature Tensor Shape (pool1) Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Displays the shape of the 'pool1' feature tensor, indicating dimensions for time, frequency, and filters. ```python features['pool1'].shape ``` -------------------------------- ### Cite musicnn for Academic Works (ISMIR2018) Source: https://github.com/jordipons/musicnn/blob/master/FAQs.md Use this BibTeX entry when citing musicnn for academic works related to the 2018 publication. ```bibtex @inproceedings{pons2018atscale, title={End-to-end learning for music audio tagging at scale}, author={Pons, Jordi and Nieto, Oriol and Prockup, Matthew and Schmidt, Erik M. and Ehmann, Andreas F. and Serra, Xavier}, booktitle={19th International Society for Music Information Retrieval Conference (ISMIR2018)}, year={2018}, } ``` -------------------------------- ### Inspect Feature Tensor Shape (pool5) Source: https://github.com/jordipons/musicnn/blob/master/vgg_example.ipynb Displays the shape of the 'pool5' feature tensor. Note that 'pool5' features are returned as 2D. ```python features['pool5'].shape ``` -------------------------------- ### Cite musicnn for Academic Works (ISMIR2019) Source: https://github.com/jordipons/musicnn/blob/master/FAQs.md Use this BibTeX entry when citing musicnn for academic works related to the 2019 publication. ```bibtex @inproceedings{pons2019musicnn, title={musicnn: pre-trained convolutional neural networks for music audio tagging}, author={Pons, Jordi and Serra, Xavier}, booktitle={Late-breaking/demo session in 20th International Society for Music Information Retrieval Conference (LBD-ISMIR2019)}, year={2019}, } ``` -------------------------------- ### Concatenate Timbral and Temporal Features Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Combines 'temporal' and 'timbral' features into a single 'frontend_features' array for further processing. Requires numpy. ```python import numpy as np frontend_features = np.concatenate([features['temporal'], features['timbral']], axis=1) ``` -------------------------------- ### Extract Music Features and Taggram Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Use this function to extract the temporal evolution of tags (taggram) and intermediate model representations (features) from a given music file. Specify the model, input length, overlap, and whether to extract features. ```python taggram, tags, features = musicnn.extractor.extractor(file_name, model='MTT_musicnn', input_length=3, input_overlap=None, extract_features=True) ``` -------------------------------- ### Visualize Mid-end CNN Features Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb Plots 'cnn1', 'cnn2', and 'cnn3' features using the depict_features function. 'cnn1' and 'cnn2' have x-axis labels disabled, while 'cnn3' has them enabled. Uses tight_layout for better spacing. ```python gs = gridspec.GridSpec(3, 1) # create a figure having 1 rows and 3 cols. depict_features(features=features['cnn1'], coordinates=gs[0, 0], title='cnn1 features', xlabel=False) depict_features(features=features['cnn2'], coordinates=gs[1, 0], title='cnn2 features', xlabel=False) depict_features(features=features['cnn3'], coordinates=gs[2, 0], title='cnn3 features') plt.tight_layout() plt.show() ``` -------------------------------- ### musicnn.extractor.extractor Source: https://github.com/jordipons/musicnn/blob/master/DOCUMENTATION.md Extracts the taggram (temporal evolution of tags) and intermediate model features from a given music file using a specified model. ```APIDOC ## musicnn.extractor.extractor ### Description Extracts the `taggram` (the temporal evolution of tags) and `features` (intermediate representations of the model) of the music-clip in `file_name` with the selected `model`. ### Method ```python taggram, tags, features = musicnn.extractor.extractor(file_name, model='MTT_musicnn', input_length=3, input_overlap=None, extract_features=True) ``` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **file_name** (string) - Required - Path to the music file to tag. Example: './audio/TRWJAZW128F42760DD_test.mp3' - **model** (string) - Optional - Select a music audio tagging model. Options: `'MTT_musicnn'`, `'MTT_vgg'`, `'MSD_musicnn'`, `'MSD_musicnn_big'` or `'MSD_vgg'`. Default: `'MTT_musicnn'` - **input_length** (float) - Optional - Length (in seconds) of the input spectrogram patches. Recommended value: 3. Example: 3.1 - **input_overlap** (float) - Optional - Amount of overlap (in seconds) of the input spectrogram patches. Example: 1.0 - **extract_features** (boolean) - Optional - Set it `True` for extracting the intermediate representations of the model. Options: `False`, `True`. Default: `True` ### Output - **taggram** (2D np.ndarray) - The temporal evolution of the tags likelihood. - **tags** (list) - List of tags corresponding to the tag-indices of the taggram. - **features** (dictionary) - If `extract_features = True`, outputs a dictionary containing the activations of the different layers the selected model has. Keys for musicnn models: ['timbral', 'temporal', 'cnn1', 'cnn2', 'cnn3', 'mean_pool', 'max_pool', 'penultimate']. Keys for vgg models: ['pool1', 'pool2', 'pool3', 'pool4', 'pool5'] ### Request Example ```json { "file_name": "./audio/TRWJAZW128F42760DD_test.mp3", "model": "MTT_musicnn", "input_length": 3.0, "input_overlap": 1.0, "extract_features": true } ``` ### Response #### Success Response - **taggram** (2D np.ndarray) - The temporal evolution of the tags likelihood. - **tags** (list) - List of tags corresponding to the tag-indices of the taggram. - **features** (dictionary) - Intermediate representations of the model if `extract_features` is True. #### Response Example ```json { "taggram": [[0.1, 0.8, 0.3], [0.2, 0.7, 0.4]], "tags": ["rock", "pop", "electronic"], "features": { "timbral": [0.5, 0.2], "temporal": [0.6, 0.3], "cnn1": [0.1, 0.9], "cnn2": [0.2, 0.8], "cnn3": [0.3, 0.7], "mean_pool": [0.4, 0.6], "max_pool": [0.5, 0.5], "penultimate": [0.7, 0.3] } } ``` ``` -------------------------------- ### Define Feature Depiction Function Source: https://github.com/jordipons/musicnn/blob/master/musicnn_example.ipynb A utility function to plot features using matplotlib. It handles image display, titles, and axis labeling for time-series feature data. Requires matplotlib. ```python %matplotlib inline import matplotlib.pylab as plt import matplotlib.gridspec as gridspec def depict_features(features, coordinates, title, aspect='auto', xlabel=True, fontsize=13): # plot features in coordinates ax = plt.subplot(coordinates) plt.imshow(features.T, interpolation=None, aspect=aspect) # set title ax.title.set_text(title + ' (' + str(features.shape[1]) + ')' ) ax.title.set_fontsize(fontsize) # y-axis ax.get_yaxis().set_visible(False) # x-axis x_label = np.arange(0, features.shape[0], features.shape[0]//5) ax.set_xticks(x_label) ax.set_xticklabels(x_label, fontsize=fontsize) if xlabel: ax.set_xlabel('(time frames)', fontsize=fontsize) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.