CLAPv2/MUSDB18-HQ
Viewer • Updated • 564 • 96 • 1
How to use Acapellas/Mini-BS-RoFormer-V2.5-46.2M with Transformers:
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("Acapellas/Mini-BS-RoFormer-V2.5-46.2M", trust_remote_code=True, device_map="auto")Model for the music source separation task, decomposes audio into four stems: bass, drums, other, and vocals.
针对音乐音频分离的 BS-RoFormer 模型,将音频分离为 bass、drums、other、vocals。
在 MUSDB18HQ 数据的 val 集上的性能(单位 SDR,越高越好):
| tracks | Mini-BS-RoFormer-V2.5-46.2M | Mini-BS-RoFormer-V2-46.8M |
|---|---|---|
| overall | 10.09 | 10.03 |
| bass | 9.71 | 9.68 |
| drums | 10.48 | 10.58 |
| other | 9.19 | 8.99 |
| vocal | 10.97 | 10.86 |
使用的 transformers 库版本为 5.18.0,PyTorch 版本为 2.14.1。为了正常运行模型还需要安装库 soundfile、einops 和 librosa。
GPU 推理:
from transformers import AutoModel
import soundfile
import torch
import librosa
model_name = "HiDolen/Mini-BS-RoFormer-V2.5-46.2M"
model = AutoModel.from_pretrained(
model_name,
trust_remote_code=True,
)
model.to("cuda")
# 加载音频
file = "./input.wav"
waveform, sr = librosa.load(file, sr=44100, mono=False)
waveform = torch.tensor(waveform).float()
waveform = waveform.to("cuda")
# 进行推理
result = model.separate(
waveform,
batch_size=2,
verbose=True,
)
# 保存处理结果
for i in range(result.shape[0]):
soundfile.write(f"separated_stem_{i}.wav", result[i].cpu().numpy().T, 44100)
以上代码会分离出 bass、drums、other 和 vocal 四个轨道。
若想只分离人声和伴奏两轨,在最后保存音频时合并即可:
···
result = model.separate(
waveform,
batch_size=2,
verbose=True,
)
# 合并 bass、drums、other 作为伴奏
instrumental = result[0] + result[1] + result[2]
vocals = result[3]
result = torch.stack([instrumental, vocals], dim=0)
for i in range(result.shape[0]):
soundfile.write(f"separated_stem_{i}.wav", result[i].cpu().numpy().T, 44100)
Mini-BS-RoFormer-V2.5 相比于 V2 的主要改进:
使用 MUSDB18HQ 数据集的 train 和 test 集进行训练。
学习率 3e-4,以 batch_size=8 训练 246k 步。
对 transformer 层使用 Muon 优化器,其他网络层使用 AdamW 优化器。