mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
127 KiB
127 KiB
In [1]:
# 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 [2]:
# clone pyannote-audio Github repository and update ROOT_DIR accordingly
ROOT_DIR = "/Users/bredin/Development/pyannote/pyannote-audio"
AUDIO_FILE = f"{ROOT_DIR}/tutorials/assets/sample.wav"In [3]:
from pyannote.database.util import load_rttm
REFERENCE = f"{ROOT_DIR}/tutorials/assets/sample.rttm"
reference = load_rttm(REFERENCE)["sample"]
referenceOut [3]:
In [4]:
from huggingface_hub import HfApi
available_models = [m.modelId for m in HfApi().list_models(filter="pyannote-audio-model")]
available_modelsOut [4]:
['pyannote/TestModelForContinuousIntegration', 'pyannote/embedding', 'pyannote/segmentation']
In [5]:
from pyannote.audio import Model
model = Model.from_pretrained("pyannote/segmentation")/Users/bredin/miniconda3/envs/pyannote/lib/python3.8/site-packages/pytorch_lightning/core/memory.py:16: LightningDeprecationWarning: `pytorch_lightning.core.memory.get_memory_profile` and `pytorch_lightning.core.memory.get_gpu_memory_map` have been moved to `pytorch_lightning.utilities.memory` since v1.5 and will be removed in v1.7. rank_zero_deprecation( /Users/bredin/miniconda3/envs/pyannote/lib/python3.8/site-packages/pytorch_lightning/core/memory.py:25: LightningDeprecationWarning: `pytorch_lightning.core.memory.LayerSummary` and `pytorch_lightning.core.memory.ModelSummary` have been moved to `pytorch_lightning.utilities.model_summary` since v1.5 and will be removed in v1.7. rank_zero_deprecation(
In [6]:
model.summarize()Out [6]:
| Name | Type | Params | In sizes | Out sizes -------------------------------------------------------------------------------------------------------- 0 | sincnet | SincNet | 42.6 K | [3, 1, 32000] | [3, 60, 115] 1 | lstm | LSTM | 1.4 M | [3, 115, 60] | [[3, 115, 256], [[8, 3, 128], [8, 3, 128]]] 2 | linear | ModuleList | 49.4 K | ? | ? 3 | classifier | Linear | 516 | [3, 115, 128] | [3, 115, 4] 4 | activation | Sigmoid | 0 | [3, 115, 4] | [3, 115, 4] -------------------------------------------------------------------------------------------------------- 1.5 M Trainable params 0 Non-trainable params 1.5 M Total params 5.892 Total estimated model params size (MB)
In [7]:
specs = model.specifications
specsOut [7]:
Specifications(problem=<Problem.MULTI_LABEL_CLASSIFICATION: 2>, resolution=<Resolution.FRAME: 1>, duration=5.0, warm_up=(0.0, 0.0), classes=['speaker#1', 'speaker#2', 'speaker#3', 'speaker#4'], permutation_invariant=True)
In [8]:
from pyannote.audio import Inference
inference = Inference(model, step=2.5)
output = inference(AUDIO_FILE)
outputOut [8]:
In [9]:
output.data.shapeOut [9]:
(11, 293, 4)
In [10]:
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 [11]:
output = inference(audio_in_memory)
outputOut [11]:
In [12]:
from pyannote.core import Segment
output = inference.crop(AUDIO_FILE, Segment(10, 20))
outputOut [12]: