mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
* chore: import Model from package root * chore: import Inference from package root
8.5 KiB
8.5 KiB
In [ ]:
# TODO: switch to AMI
PROTOCOL = 'Debug.SpeakerDiarization.Debug'In [ ]:
# TODO: update this tutorial to do fine tuning of a model pretrained on DIHARDIn [ ]:
from pyannote.database import get_protocol, FileFinder
protocol = get_protocol(PROTOCOL, preprocessors={"audio": FileFinder()})In [ ]:
first_training_file = next(protocol.train())In [ ]:
from pyannote.audio.utils.preview import listen
listen(first_training_file)In [ ]:
first_training_file['annotation']In [ ]:
from pyannote.audio.pipelines.overlapped_speech_detection import OracleOverlappedSpeechDetection
oracle_osd = OracleOverlappedSpeechDetection()
oracle_osd(first_training_file).get_timeline()In [ ]:
from pyannote.audio.tasks import OverlappedSpeechDetection
osd = OverlappedSpeechDetection(protocol, duration=2., batch_size=16)In [ ]:
from pyannote.audio.models.segmentation.debug import SimpleSegmentationModel
model = SimpleSegmentationModel(task=osd)In [ ]:
import pytorch_lightning as pl
trainer = pl.Trainer(max_epochs=10)
trainer.fit(model, osd)In [ ]:
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 [ ]:
from pyannote.audio import Inference
inference = Inference(model)
osd_probability = inference(test_file)In [ ]:
osd_probabilityIn [ ]:
from pyannote.audio.pipelines import OverlappedSpeechDetection as OverlappedSpeechDetectionPipeline
pipeline = OverlappedSpeechDetectionPipeline(scores=inference).instantiate(
{"onset": 0.5, "offset": 0.5, "min_duration_on": 0.1, "min_duration_off": 0.1})In [ ]:
pipeline(test_file).get_timeline()In [ ]:
# to make things faster, we run the inference once and for all...
validation_files = list(protocol.development())
for file in validation_files:
file['osd'] = inference(file)
# ... and tell the pipeline to load OSD scores directly from files
pipeline = OverlappedSpeechDetectionPipeline(scores="osd")In [ ]:
from pyannote.pipeline import Optimizer
optimizer = Optimizer(pipeline)
optimizer.tune(validation_files, n_iterations=200, show_progress=False)In [ ]:
optimized_pipeline = OverlappedSpeechDetectionPipeline(scores=inference).instantiate(optimizer.best_params)
optimized_pipeline(test_file).get_timeline()