mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
160 KiB
160 KiB
In [3]:
# preparing notebook for visualization purposes
# (only show outputs between t=0s and t=30s)
from pyannote.core import notebook, Segment
notebook.crop = Segment(0, 30)In [ ]:
!pip install -qq pyannote.audio==3.1.1
!pip install -qq ipython==7.34.0
!wget -q "https://github.com/pyannote/pyannote-audio/raw/develop/tutorials/assets/sample.wav"
!wget -q "https://github.com/pyannote/pyannote-audio/raw/develop/tutorials/assets/sample.rttm"
!wget -q -P ./assets/ "https://github.com/pyannote/pyannote-audio/blob/develop/tutorials/assets/download-model.png"In [18]:
AUDIO_FILE = "sample.wav"
REFERENCE = "sample.rttm"In [2]:
# clone pyannote-audio Github repository and update ROOT_DIR accordingly
ROOT_DIR = "<path-to-pyannote-github-repo>/pyannote-audio"
AUDIO_FILE = f"{ROOT_DIR}/tutorials/assets/sample.wav"
REFERENCE = f"{ROOT_DIR}/tutorials/assets/sample.rttm"In [4]:
from pyannote.database.util import load_rttm
reference = load_rttm(REFERENCE)["sample"]
referenceOut [4]:
In [5]:
from huggingface_hub import HfApi
available_models = [m.modelId for m in HfApi().list_models(filter="pyannote-audio-model")]
list(filter(lambda p: p.startswith("pyannote/"), available_models))Out [5]:
['pyannote/TestModelForContinuousIntegration', 'pyannote/embedding', 'pyannote/segmentation', 'pyannote/brouhaha', 'pyannote/segmentation-3.0', 'pyannote/wespeaker-voxceleb-resnet34-LM']
In [ ]:
from huggingface_hub import notebook_login
notebook_login()In [ ]:
from pyannote.audio import Model
model = Model.from_pretrained("pyannote/segmentation-3.0", use_auth_token=True)In [8]:
from pytorch_lightning.utilities.model_summary import summarize
summarize(model)Out [8]:
| Name | Type | Params | In sizes | Out sizes --------------------------------------------------------------------------------------------------------- 0 | sincnet | SincNet | 42.6 K | [1, 1, 160000] | [1, 60, 589] 1 | lstm | LSTM | 1.4 M | [1, 589, 60] | [[1, 589, 256], [[8, 1, 128], [8, 1, 128]]] 2 | linear | ModuleList | 49.4 K | ? | ? 3 | classifier | Linear | 903 | [1, 589, 128] | [1, 589, 7] 4 | activation | LogSoftmax | 0 | [1, 589, 7] | [1, 589, 7] --------------------------------------------------------------------------------------------------------- 1.5 M Trainable params 0 Non-trainable params 1.5 M Total params 5.893 Total estimated model params size (MB)
In [9]:
specs = model.specifications
specsOut [9]:
Specifications(problem=<Problem.MONO_LABEL_CLASSIFICATION: 1>, resolution=<Resolution.FRAME: 1>, duration=10.0, min_duration=None, warm_up=(0.0, 0.0), classes=['speaker#1', 'speaker#2', 'speaker#3'], powerset_max_classes=2, permutation_invariant=True)
In [10]:
from pyannote.audio import Inference
inference = Inference(model, step=2.5)
output = inference(AUDIO_FILE)
outputOut [10]:
In [11]:
output.data.shapeOut [11]:
(9, 589, 3)
In [12]:
import torchaudio
waveform, sample_rate = torchaudio.load(AUDIO_FILE)
print(f"{type(waveform)=}")
print(f"{waveform.shape=}")
print(f"{waveform.dtype=}")
audio_in_memory = {"waveform": waveform, "sample_rate": sample_rate}type(waveform)=<class 'torch.Tensor'> waveform.shape=torch.Size([1, 480000]) waveform.dtype=torch.float32
In [13]:
output = inference(audio_in_memory)
outputOut [13]:
In [19]:
from pyannote.core import Segment
output = inference.crop(audio_in_memory, Segment(0, 20))
outputOut [19]:
In [ ]:
# look ma: no hands!
offline_model = Model.from_pretrained("pytorch_model.bin")In [ ]:
# just checking weights are the same...
import torch
for weights, offline_weights in zip(model.parameters(), offline_model.parameters()):
assert torch.equal(weights, offline_weights)