File size: 1,983 Bytes
0bbc70a
 
 
 
 
 
 
 
 
42413d8
 
0bbc70a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
license: apache-2.0
tags:
- audio
- music
- music-tagging
- pytorch
---

(Backup of https://huggingface.co/oriyonay/musicnn-pytorch)

# MusicNN-PyTorch

This is a PyTorch reimplementation of the [MusicNN](https://github.com/jordipons/musicnn) library for music audio tagging.

It contains the model architecture and converted weights from the original TensorFlow 1.x checkpoints.

## Supported Models

- `MTT_musicnn`: Trained on MagnaTagATune (50 tags) - **Default model**
- `MSD_musicnn`: Trained on Million Song Dataset (50 tags)
- `MSD_musicnn_big`: Larger version trained on MSD (512 filters)

## Super Simple Usage (Hugging Face Transformers)

```python
from transformers import AutoModel

# Load the model (downloads automatically)
model = AutoModel.from_pretrained("oriyonay/musicnn-pytorch", trust_remote_code=True)

# Use the model
tags = model.predict_tags("your_audio.mp3", top_k=5)
print(f"Top 5 tags: {tags}")
```

## Embeddings (Optional)

```python
from transformers import AutoModel

model = AutoModel.from_pretrained("oriyonay/musicnn-pytorch", trust_remote_code=True)

# Extract embeddings from any layer
emb = model.extract_embeddings("your_audio.mp3", layer="penultimate", pool="mean")
print(emb.shape)
```

## Colab Example

```python
# Install dependencies
!pip install transformers torch librosa soundfile

# Load with AutoModel
from transformers import AutoModel
model = AutoModel.from_pretrained("oriyonay/musicnn-pytorch", trust_remote_code=True)

# Use the model
tags = model.predict_tags("your_audio.mp3", top_k=5)
print(tags)
```

## Traditional Usage

If you prefer to download the code manually:

```python
from musicnn_torch import top_tags

# Get top 5 tags for an audio file
tags = top_tags('path/to/audio.mp3', model='MTT_musicnn', topN=5)
print(tags)
```

## Installation

```bash
pip install transformers torch librosa soundfile
```

## Credits

Original implementation by [Jordi Pons](https://github.com/jordipons).
PyTorch port by Gemini.