Downloads · 30 days
57
12% of all-time downloads
onnx-community/Musical-Instrument-Classification-ONNX
Musical-Instrument-Classification-ONNX is a audio classification model from onnx-community. Use it for the audio classification task on the model card, and read the license before you ship it in a product. It is set up for transformers.js. The card lists the license as mit.
This is an ONNX version of Bhaveen/Musical-Instrument-Classification. It was automatically converted and uploaded using this Hugging Face Space.
Downloads · 30 days
57
12% of all-time downloads
All-time downloads
468
Public
Repo size
1 GB
Likes
0
Public
Click a slice to open those files.
.onnx1.1 GB · 100%
From the Hugging Face model README
This is an ONNX version of Bhaveen/Musical-Instrument-Classification. It was automatically converted and uploaded using this Hugging Face Space.
See the pipeline documentation for audio-classification: https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.AudioClassificationPipeline
This model is a fine-tuned version of facebook/wav2vec2-base-960h for musical instrument classification. It can identify 9 different musical instruments from audio recordings with high accuracy.
The model achieves excellent performance on the evaluation set after 5 epochs of training:
| Epoch | Training Loss | Validation Loss | ROC AUC | Accuracy |
|---|---|---|---|---|
| 1 | 1.9872 | 1.8875 | 0.9248 | 0.6639 |
| 2 | 1.8652 | 1.4793 | 0.9799 | 0.8000 |
| 3 | 1.3868 | 1.2311 | 0.9861 | 0.8194 |
| 4 | 1.3242 | 1.1121 | 0.9827 | 0.9250 |
| 5 | 1.1869 | 1.0639 | 0.9859 | 0.9333 |
The model can classify the following 9 musical instruments:
from transformers import pipeline
import torchaudio
# Load the classification pipeline
classifier = pipeline("audio-classification", model="Bhaveen/epoch_musical_instruments_identification_2")
# Load and preprocess audio
audio, rate = torchaudio.load("your_audio_file.wav")
transform = torchaudio.transforms.Resample(rate, 16000)
audio = transform(audio).numpy().reshape(-1)[:48000]
# Classify the audio
result = classifier(audio)
print(result)
from transformers import AutoFeatureExtractor, AutoModelForAudioClassification
import torchaudio
import torch
# Load model and feature extractor
model_name = "Bhaveen/epoch_musical_instruments_identification_2"
feature_extractor = AutoFeatureExtractor.from_pretrained(model_name)
model = AutoModelForAudioClassification.from_pretrained(model_name)
# Load and preprocess audio
audio, rate = torchaudio.load("your_audio_file.wav")
transform = torchaudio.transforms.Resample(rate, 16000)
audio = transform(audio).numpy().reshape(-1)[:48000]
# Extract features and make prediction
inputs = feature_extractor(audio, sampling_rate=16000, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
predicted_class = torch.argmax(predictions, dim=-1)
print(f"Predicted instrument: {model.config.id2label[predicted_class.item()]}")
# Training hyperparameters
batch_size = 1
gradient_accumulation_steps = 4
learning_rate = 5e-6
num_train_epochs = 5
warmup_steps = 50
weight_decay = 0.02
The model uses the following evaluation metrics:
The repository contains:
Model trained as part of a hackathon project