mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
147 KiB
147 KiB
In [ ]:
!pip install -qq pyannote.audio==3.1.1
!pip install -qq ipython==7.34.0
!git clone https://github.com/pyannote/AMI-diarization-setup.git
%cd ./AMI-diarization-setup/pyannote/
!bash ./download_ami_mini.sh
%cd /contentIn [ ]:
from pyannote.database import registry, FileFinder
registry.load_database("AMI-diarization-setup/pyannote/database.yml")
protocol = registry.get_protocol("AMI.SpeakerDiarization.mini", preprocessors={"audio": FileFinder()})In [24]:
first_training_file = next(protocol.train())In [ ]:
from pyannote.audio.utils.preview import listen
listen(first_training_file)In [26]:
first_training_file['annotation']Out [26]:
In [27]:
from pyannote.audio.pipelines.overlapped_speech_detection import OracleOverlappedSpeechDetection
oracle_osd = OracleOverlappedSpeechDetection()
oracle_osd(first_training_file).get_timeline()Out [27]:
In [ ]:
from pyannote.audio.tasks import OverlappedSpeechDetection
osd = OverlappedSpeechDetection(protocol, duration=2., batch_size=16)In [ ]:
from huggingface_hub import notebook_login
notebook_login()In [30]:
from pyannote.audio.core.model import Model
pretrained_model = Model.from_pretrained("pyannote/segmentation-3.0", token=True)
# we assign the OSD task to the model
pretrained_model.task = osdIn [33]:
import pytorch_lightning as pl
trainer = pl.Trainer(max_epochs=1)
trainer.fit(pretrained_model)GPU available: False, used: False TPU available: False, using: 0 TPU cores IPU available: False, using: 0 IPUs HPU available: False, using: 0 HPUs
| Name | Type | Params | In sizes | Out sizes --------------------------------------------------------------------------------------------------------------------- 0 | sincnet | SincNet | 42.6 K | [1, 1, 32000] | [1, 60, 115] 1 | lstm | LSTM | 1.4 M | [1, 115, 60] | [[1, 115, 256], [[8, 1, 128], [8, 1, 128]]] 2 | linear | ModuleList | 49.4 K | ? | ? 3 | classifier | Linear | 129 | [1, 115, 128] | [1, 115, 1] 4 | activation | Sigmoid | 0 | [1, 115, 1] | [1, 115, 1] 5 | validation_metric | MetricCollection | 0 | ? | ? --------------------------------------------------------------------------------------------------------------------- 1.5 M Trainable params 0 Non-trainable params 1.5 M Total params 5.890 Total estimated model params size (MB)
Sanity Checking: | | 0/? [00:00<?, ?it/s]
Training: | | 0/? [00:00<?, ?it/s]
Validation: | | 0/? [00:00<?, ?it/s]
`Trainer.fit` stopped: `max_epochs=1` reached.
In [34]:
test_file = next(protocol.test())
# here we use a test file provided by the protocol, but it could be any audio file
# e.g. test_file = "/path/to/test.wav".
In [35]:
oracle_osd(test_file).get_timeline()Out [35]:
In [36]:
from pyannote.audio import Inference
inference = Inference(pretrained_model)
osd_probability = inference(test_file)In [37]:
osd_probabilityOut [37]:
In [38]:
from pyannote.audio.pipelines import OverlappedSpeechDetection as OverlappedSpeechDetectionPipeline
pipeline = OverlappedSpeechDetectionPipeline(pretrained_model).instantiate(
{"onset": 0.5, "offset": 0.5, "min_duration_on": 0.1, "min_duration_off": 0.1})In [39]:
pipeline(test_file).get_timeline()Out [39]:
In [40]:
from pyannote.pipeline import Optimizer
validation_files = list(protocol.development())
optimizer = Optimizer(pipeline)
optimizer.tune(validation_files, n_iterations=200, show_progress=False)Out [40]:
{'loss': 0.7273619100616171,
'params': {'onset': 0.4321866835452871,
'offset': 0.33656592926710593,
'min_duration_on': 0.11171631479481339,
'min_duration_off': 0.07311754878841395}}In [41]:
optimized_pipeline = OverlappedSpeechDetectionPipeline(pretrained_model).instantiate(optimizer.best_params)
optimized_pipeline(test_file).get_timeline()Out [41]: