mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
feat: add Hydra-based "pyannote-audio-train" CLI
* closes #476 (CLI) * closes #514 (support for AutoLR) * closes #485 (hyper-parameter optimization with Hydra’s Ax sweeper) * closes #412 (log graph to Tensorboard)
This commit is contained in:
1 parent
298ba39b5e
commit
06d3b6116c
28 files changed
+449
-46
No files matched your search
@@ -0,0 +1,4 @@
|
||||
recursive-include pyannote *.py
|
||||
recursive-include pyannote *.yaml
|
||||
global-exclude *.pyc
|
||||
global-exclude __pycache__
|
||||
@@ -1,6 +1,14 @@
|
||||
# pyannote-audio-v2
|
||||
Rewriting pyannote.audio from scratch
|
||||
|
||||
|
||||
## CLI
|
||||
|
||||
```bash
|
||||
pyannote-audio-train task=vad model=debug protocol=Debug.SpeakerDiarization.Debug
|
||||
```
|
||||
|
||||
|
||||
## Contributing
|
||||
|
||||
The commands below will setup pre-commit hooks and packages needed for developing the `pyannote.audio` library.
|
||||
@@ -12,8 +20,8 @@ pre-commit install
|
||||
|
||||
## Testing
|
||||
|
||||
Tests rely on a set of debugging files available in [`test/data`](test/data) directory.
|
||||
Set `PYANNOTE_DATABASE_CONFIG` environment variable to `test/data/database.yml` before running tests:
|
||||
Tests rely on a set of debugging files available in [`test/data`](test/data) directory.
|
||||
Set `PYANNOTE_DATABASE_CONFIG` environment variable to `test/data/database.yml` before running tests:
|
||||
|
||||
```bash
|
||||
PYANNOTE_DATABASE_CONFIG=tests/data/database.yml pytest
|
||||
|
||||
@@ -147,7 +147,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from pyannote.audio.tasks.speaker_verification.task import SpeakerEmbeddingArcFace\n",
|
||||
"emb = SpeakerEmbeddingArcFace(protocol, duration=2., batch_size=32, num_workers=4)\n",
|
||||
"emb = SpeakerEmbeddingArcFace(protocol, duration=2., num_workers=4)\n",
|
||||
"model = SimpleEmbeddingModel(task=emb)\n",
|
||||
"trainer = pl.Trainer(max_epochs=1)\n",
|
||||
"_ = trainer.fit(model, emb)"
|
||||
|
||||
@@ -146,7 +146,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from pyannote.audio.tasks.speaker_verification.task import SpeakerEmbeddingArcFace\n",
|
||||
"emb = SpeakerEmbeddingArcFace(protocol, duration=2., batch_size=32, num_workers=4)\n",
|
||||
"emb = SpeakerEmbeddingArcFace(protocol, duration=2., num_workers=4)\n",
|
||||
"from pyannote.audio.models.debug import SimpleEmbeddingModel\n",
|
||||
"model = SimpleEmbeddingModel(task=emb)\n",
|
||||
"trainer = pl.Trainer(max_epochs=1, default_root_dir='inference/emb')\n",
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,111 @@
|
||||
# MIT License
|
||||
#
|
||||
# Copyright (c) 2020 CNRS
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
|
||||
from typing import Iterable
|
||||
|
||||
import hydra
|
||||
from hydra.utils import instantiate
|
||||
from omegaconf import DictConfig
|
||||
from pytorch_lightning.callbacks import EarlyStopping, ModelCheckpoint
|
||||
from pytorch_lightning.loggers import TensorBoardLogger
|
||||
from torch.nn import Parameter
|
||||
from torch.optim import Optimizer
|
||||
|
||||
from pyannote.database import FileFinder, get_protocol
|
||||
|
||||
|
||||
@hydra.main(config_path="train_config", config_name="config")
|
||||
def main(cfg: DictConfig) -> None:
|
||||
|
||||
protocol = get_protocol(cfg.protocol, preprocessors={"audio": FileFinder()})
|
||||
|
||||
# TODO: configure augmentation
|
||||
# TODO: configure scheduler
|
||||
# TODO: configure layer freezing
|
||||
|
||||
def optimizer(parameters: Iterable[Parameter], lr: float = 1e-3) -> Optimizer:
|
||||
return instantiate(cfg.optimizer, parameters, lr=lr)
|
||||
|
||||
task = instantiate(
|
||||
cfg.task,
|
||||
protocol,
|
||||
optimizer=optimizer,
|
||||
learning_rate=cfg.optimizer.lr,
|
||||
)
|
||||
|
||||
model = instantiate(cfg.model, task=task)
|
||||
|
||||
monitor, mode = task.validation_monitor
|
||||
model_checkpoint = ModelCheckpoint(
|
||||
monitor=monitor,
|
||||
mode=mode,
|
||||
save_top_k=10,
|
||||
period=1,
|
||||
save_last=True,
|
||||
save_weights_only=False,
|
||||
dirpath=".",
|
||||
filename=f"{{epoch}}-{{{monitor}:.3f}}",
|
||||
verbose=cfg.verbose,
|
||||
)
|
||||
|
||||
early_stopping = EarlyStopping(
|
||||
monitor=monitor,
|
||||
mode=mode,
|
||||
min_delta=0.0,
|
||||
patience=10,
|
||||
strict=True,
|
||||
verbose=cfg.verbose,
|
||||
)
|
||||
|
||||
logger = TensorBoardLogger(
|
||||
".",
|
||||
name="",
|
||||
version="",
|
||||
log_graph=True,
|
||||
)
|
||||
|
||||
trainer = instantiate(
|
||||
cfg.trainer,
|
||||
callbacks=[model_checkpoint, early_stopping],
|
||||
logger=logger,
|
||||
)
|
||||
|
||||
if cfg.trainer.auto_lr_find == True:
|
||||
# HACK: these two lines below should be removed once
|
||||
# the corresponding bug is fixed in pytorch-lighting.
|
||||
# https://github.com/pyannote/pyannote-audio/issues/514
|
||||
task.setup(stage="fit")
|
||||
model.setup(stage="fit")
|
||||
trainer.tune(model, task)
|
||||
|
||||
trainer.fit(model, task)
|
||||
|
||||
best_monitor = float(early_stopping.best_score)
|
||||
if mode == "min":
|
||||
return best_monitor
|
||||
else:
|
||||
return -best_monitor
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Whitespace-only changes.
@@ -0,0 +1,10 @@
|
||||
|
||||
protocol: ???
|
||||
verbose: False
|
||||
|
||||
defaults:
|
||||
- task: vad
|
||||
- model: debug
|
||||
- optimizer: adam
|
||||
- trainer: default
|
||||
- hydra: train
|
||||
@@ -0,0 +1,80 @@
|
||||
# @package _group_
|
||||
|
||||
run:
|
||||
# dir: train/${now:%Y-%m-%d}/${now:%H-%M-%S}
|
||||
dir: ${protocol}/${task._target_}/${now:%Y-%m-%d}/${now:%H-%M-%S}
|
||||
|
||||
sweep:
|
||||
dir: multirun/${now:%Y-%m-%d}/${now:%H-%M-%S}/${protocol}/${task._target_}
|
||||
subdir: ${hydra.job.num}
|
||||
|
||||
output_subdir: ""
|
||||
|
||||
help:
|
||||
app_name: pyannote-audio-train
|
||||
|
||||
# Help header, customize to describe your app to your users
|
||||
header: == ${hydra.help.app_name} ==
|
||||
|
||||
footer: |-
|
||||
Powered by Hydra (https://hydra.cc)
|
||||
Use --hydra-help to view Hydra specific help
|
||||
|
||||
template: |-
|
||||
${hydra.help.header}
|
||||
|
||||
pyannote-audio-train protocol={protocol_name} task={task} model={model}
|
||||
|
||||
{task} can be any of the following:
|
||||
* vad (default) = voice activity detection
|
||||
* scd = speaker change detection
|
||||
* osd = overlapped speech detection
|
||||
* xseg = multi-task segmentation
|
||||
|
||||
{model} can be any of the following:
|
||||
* debug (default) = simple segmentation model for debugging purposes
|
||||
|
||||
{optimizer} can be any of the following
|
||||
* adam (default) = Adam optimizer
|
||||
|
||||
{trainer} can be any of the following
|
||||
* fast_dev_run for debugging
|
||||
* default (default) for training the model
|
||||
|
||||
Options
|
||||
=======
|
||||
|
||||
Here, we describe the most common options: use "--cfg job" option to get a complete list.
|
||||
|
||||
* task.duration: audio chunk duration (in seconds)
|
||||
* task.batch_size: number of audio chunks per batch
|
||||
* task.num_workers: number of workers used for generating training chunks
|
||||
|
||||
* optimizer.lr: learning rate
|
||||
* trainer.auto_lr_find: use pytorch-lightning AutoLR
|
||||
|
||||
Hyper-parameter optimization
|
||||
============================
|
||||
|
||||
Because it is powered by Hydra (https://hydra.cc), one can run grid search using the --multirun option.
|
||||
|
||||
For instance, the following command will run the same job three times, with three different learning rates:
|
||||
pyannote-audio-train --multirun protocol={protocol_name} task={task} optimizer.lr=1e-3,1e-2,1e-1
|
||||
|
||||
Even better, one can use Ax (https://ax.dev) sweeper to optimize learning rate directly:
|
||||
pyannote-audio-train --multirun hydra/sweeper=ax protocol={protocol_name} task={task} optimizer.lr="interval(1e-3, 1e-1)"
|
||||
|
||||
See https://hydra.cc/docs/plugins/ax_sweeper for more details.
|
||||
|
||||
User-defined task or model
|
||||
==========================
|
||||
|
||||
1. define your_package.YourTask (or your_package.YourModel) class
|
||||
2. create file /path/to/your_config/task/your_task.yaml (or /path/to/your_config/model/your_model.yaml)
|
||||
# @package _group_
|
||||
_target_: your_package.YourTask # or YourModel
|
||||
param1: value1
|
||||
param2: value2
|
||||
3. call pyannote-audio-train --config-dir /path/to/your_config task=your_task task.param1=modified_value1 model=your_model ...
|
||||
|
||||
${hydra.help.footer}
|
||||
@@ -0,0 +1,2 @@
|
||||
# @package _group_
|
||||
_target_: pyannote.audio.models.PyanNet
|
||||
@@ -0,0 +1,2 @@
|
||||
# @package _group_
|
||||
_target_: pyannote.audio.models.debug.SimpleSegmentationModel
|
||||
@@ -0,0 +1,7 @@
|
||||
# @package _group_
|
||||
_target_: torch.optim.Adam
|
||||
lr: 1e-3
|
||||
betas: [0.9, 0.999]
|
||||
eps: 1e-08
|
||||
weight_decay: 0
|
||||
amsgrad: False
|
||||
@@ -0,0 +1,2 @@
|
||||
# @package _group_
|
||||
_target_: pyannote.audio.tasks.OverlappedSpeechDetection
|
||||
@@ -0,0 +1,2 @@
|
||||
# @package _group_
|
||||
_target_: pyannote.audio.tasks.SpeakerChangeDetection
|
||||
@@ -0,0 +1,2 @@
|
||||
# @package _group_
|
||||
_target_: pyannote.audio.tasks.VoiceActivityDetection
|
||||
@@ -0,0 +1,2 @@
|
||||
# @package _group_
|
||||
_target_: pyannote.audio.tasks.MultiTaskSegmentation
|
||||
@@ -0,0 +1,45 @@
|
||||
# @package _group_
|
||||
_target_: pytorch_lightning.Trainer
|
||||
#accelerator: None
|
||||
accumulate_grad_batches: 1
|
||||
amp_backend: 'native'
|
||||
amp_level: 'O2'
|
||||
auto_lr_find: False
|
||||
auto_scale_batch_size: False
|
||||
auto_select_gpus: True
|
||||
benchmark: True
|
||||
check_val_every_n_epoch: 1
|
||||
checkpoint_callback: True
|
||||
deterministic: False
|
||||
fast_dev_run: False
|
||||
flush_logs_every_n_steps: 100
|
||||
#gpus: None
|
||||
gradient_clip_val: 0
|
||||
limit_test_batches: 1.0
|
||||
limit_train_batches: 1.0
|
||||
limit_val_batches: 1.0
|
||||
log_every_n_steps: 50
|
||||
#log_gpu_memory: None
|
||||
max_epochs: 1000
|
||||
#max_steps: None
|
||||
min_epochs: 1
|
||||
#min_steps: None
|
||||
num_nodes: 1
|
||||
num_processes: 1
|
||||
num_sanity_val_steps: 2
|
||||
overfit_batches: 0.0
|
||||
precision: 32
|
||||
prepare_data_per_node: True
|
||||
process_position: 0
|
||||
#profiler: None
|
||||
progress_bar_refresh_rate: 1
|
||||
reload_dataloaders_every_epoch: False
|
||||
replace_sampler_ddp: True
|
||||
sync_batchnorm: False
|
||||
terminate_on_nan: False
|
||||
#tpu_cores: None
|
||||
track_grad_norm: -1
|
||||
#truncated_bptt_steps: None
|
||||
val_check_interval: 1.0
|
||||
#weights_save_path: None
|
||||
weights_summary: 'top'
|
||||
@@ -0,0 +1,3 @@
|
||||
# @package _group_
|
||||
_target_: pytorch_lightning.Trainer
|
||||
fast_dev_run: True
|
||||
@@ -136,6 +136,11 @@ class Model(pl.LightningModule):
|
||||
# (e.g. the final classification and activation layers)
|
||||
pass
|
||||
|
||||
# used by Tensorboard logger to log model graph
|
||||
@cached_property
|
||||
def example_input_array(self) -> torch.Tensor:
|
||||
return self.task.example_input_array
|
||||
|
||||
def helper_introspect(
|
||||
self,
|
||||
specifications: TaskSpecification,
|
||||
@@ -299,6 +304,10 @@ class Model(pl.LightningModule):
|
||||
# so that its dataloader knows how to generate targets
|
||||
self.task.model_introspection = self.hparams.model_introspection
|
||||
|
||||
# this is needed to support pytorch-lightning auto_lr_find feature
|
||||
# as it expects to find a "learning_rate" entry in model.hparams
|
||||
self.hparams.learning_rate = self.task.learning_rate
|
||||
|
||||
def on_save_checkpoint(self, checkpoint):
|
||||
|
||||
# put everything pyannote.audio-specific under pyannote.audio
|
||||
|
||||
@@ -28,12 +28,13 @@ import warnings
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from functools import cached_property
|
||||
from typing import TYPE_CHECKING, List, Optional, Text
|
||||
from typing import TYPE_CHECKING, Callable, Iterable, List, Optional, Text
|
||||
|
||||
import pytorch_lightning as pl
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import torch.optim
|
||||
from torch.nn import Parameter
|
||||
from torch.optim import Adam, Optimizer
|
||||
from torch.utils.data import DataLoader, IterableDataset
|
||||
|
||||
from pyannote.database import Protocol
|
||||
@@ -86,21 +87,26 @@ class TrainDataset(IterableDataset):
|
||||
def __init__(self, task: Task):
|
||||
super().__init__()
|
||||
self.task = task
|
||||
|
||||
def __iter__(self):
|
||||
return self.task.train__iter__()
|
||||
|
||||
def __len__(self):
|
||||
return self.task.train__len__()
|
||||
|
||||
|
||||
|
||||
class ValDataset(IterableDataset):
|
||||
def __init__(self, task: Task):
|
||||
super().__init__()
|
||||
self.task = task
|
||||
|
||||
def __iter__(self):
|
||||
return self.task.val__iter__()
|
||||
|
||||
def __len__(self):
|
||||
return self.task.val__len__()
|
||||
|
||||
|
||||
|
||||
class Task(pl.LightningDataModule):
|
||||
"""Base task class
|
||||
|
||||
@@ -122,13 +128,18 @@ class Task(pl.LightningDataModule):
|
||||
duration : float, optional
|
||||
Chunks duration. Defaults to variable duration (None).
|
||||
batch_size : int, optional
|
||||
Number of training samples per batch.
|
||||
Number of training samples per batch. Defaults to 32.
|
||||
num_workers : int, optional
|
||||
Number of workers used for generating training samples.
|
||||
pin_memory : bool, optional
|
||||
If True, data loaders will copy tensors into CUDA pinned
|
||||
memory before returning them. See pytorch documentation
|
||||
for more details. Defaults to False.
|
||||
optimizer : callable, optional
|
||||
Callable that takes model parameters as input and returns
|
||||
an Optimizer instance. Defaults to `torch.optim.Adam`.
|
||||
learning_rate : float, optional
|
||||
Learning rate. Defaults to 1e-3.
|
||||
|
||||
Attributes
|
||||
----------
|
||||
@@ -142,9 +153,11 @@ class Task(pl.LightningDataModule):
|
||||
self,
|
||||
protocol: Protocol,
|
||||
duration: float = None,
|
||||
batch_size: int = None,
|
||||
batch_size: int = 32,
|
||||
num_workers: int = 1,
|
||||
pin_memory: bool = False,
|
||||
optimizer: Callable[[Iterable[Parameter]], Optimizer] = None,
|
||||
learning_rate: float = 1e-3,
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
@@ -172,6 +185,11 @@ class Task(pl.LightningDataModule):
|
||||
|
||||
self.pin_memory = pin_memory
|
||||
|
||||
if optimizer is None:
|
||||
optimizer = Adam
|
||||
self.optimizer = optimizer
|
||||
self.learning_rate = learning_rate
|
||||
|
||||
def prepare_data(self):
|
||||
"""Use this to download and prepare data
|
||||
|
||||
@@ -384,9 +402,35 @@ class Task(pl.LightningDataModule):
|
||||
model.log("val_loss", loss)
|
||||
return {"loss": loss}
|
||||
|
||||
def parameters(self, model: Model) -> Iterable[Parameter]:
|
||||
return model.parameters()
|
||||
|
||||
# default configure_optimizers provided for convenience
|
||||
# can obviously be overriden for each task
|
||||
def configure_optimizers(self, model: Model):
|
||||
# for tasks such as SpeakerEmbedding,
|
||||
# other parameters should be added here
|
||||
return torch.optim.Adam(model.parameters(), lr=1e-3)
|
||||
# this is needed to support pytorch-lightning auto_lr_find feature
|
||||
# as it modifies model.hparams.learning_rate and not task.learning_rate.
|
||||
# in case one does not use auto_lr_find, Model.setup() takes care of
|
||||
# setting model.hparams.learning_rate to task.learning_rate so we are safe.
|
||||
lr = model.hparams.learning_rate
|
||||
return self.optimizer(self.parameters(model), lr=lr)
|
||||
|
||||
@property
|
||||
def validation_monitor(self):
|
||||
"""Quantity (and direction) to monitor
|
||||
|
||||
Useful for model checkpointing or early stopping.
|
||||
|
||||
Returns
|
||||
-------
|
||||
monitor : str
|
||||
Name of quantity to monitor.
|
||||
mode : {'min', 'max}
|
||||
Minimize
|
||||
|
||||
See also
|
||||
--------
|
||||
pytorch_lightning.callbacks.ModelCheckpoint
|
||||
pytorch_lightning.callbacks.EarlyStopping
|
||||
"""
|
||||
return "val_loss", "min"
|
||||
@@ -22,9 +22,11 @@
|
||||
|
||||
|
||||
import random
|
||||
from typing import Mapping
|
||||
from typing import Callable, Iterable, Mapping
|
||||
|
||||
import numpy as np
|
||||
from torch.nn import Parameter
|
||||
from torch.optim import Optimizer
|
||||
|
||||
from pyannote.audio.core.io import Audio
|
||||
from pyannote.audio.core.task import Task
|
||||
@@ -76,13 +78,18 @@ class MultiTaskSegmentation(SegmentationTaskMixin, Task):
|
||||
Additional osd-specific parameters. Has no effect when `osd` is False.
|
||||
See OverlappedSpeechDetection docstring for details and default value.
|
||||
batch_size : int, optional
|
||||
Number of training samples per batch.
|
||||
Number of training samples per batch. Defaults to 32.
|
||||
num_workers : int, optional
|
||||
Number of workers used for generating training samples.
|
||||
pin_memory : bool, optional
|
||||
If True, data loaders will copy tensors into CUDA pinned
|
||||
memory before returning them. See pytorch documentation
|
||||
for more details. Defaults to False.
|
||||
optimizer : callable, optional
|
||||
Callable that takes model parameters as input and returns
|
||||
an Optimizer instance. Defaults to `torch.optim.Adam`.
|
||||
learning_rate : float, optional
|
||||
Learning rate. Defaults to 1e-3.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@@ -95,9 +102,11 @@ class MultiTaskSegmentation(SegmentationTaskMixin, Task):
|
||||
scd_params: Mapping = None,
|
||||
osd: bool = False,
|
||||
osd_params: Mapping = None,
|
||||
batch_size: int = None,
|
||||
batch_size: int = 32,
|
||||
num_workers: int = 1,
|
||||
pin_memory: bool = False,
|
||||
optimizer: Callable[[Iterable[Parameter]], Optimizer] = None,
|
||||
learning_rate: float = 1e-3,
|
||||
):
|
||||
|
||||
super().__init__(
|
||||
@@ -106,6 +115,8 @@ class MultiTaskSegmentation(SegmentationTaskMixin, Task):
|
||||
batch_size=batch_size,
|
||||
num_workers=num_workers,
|
||||
pin_memory=pin_memory,
|
||||
optimizer=optimizer,
|
||||
learning_rate=learning_rate,
|
||||
)
|
||||
|
||||
self.vad = vad
|
||||
|
||||
@@ -22,8 +22,11 @@
|
||||
|
||||
|
||||
import random
|
||||
from typing import Callable, Iterable
|
||||
|
||||
import numpy as np
|
||||
from torch.nn import Parameter
|
||||
from torch.optim import Optimizer
|
||||
|
||||
from pyannote.audio.core.io import Audio
|
||||
from pyannote.audio.core.task import Problem, Scale, Task, TaskSpecification
|
||||
@@ -65,13 +68,18 @@ class OverlappedSpeechDetection(SegmentationTaskMixin, Task):
|
||||
(i.e. share the same file[domain] value). Default behavior is to not contrain
|
||||
data augmentation with regards to domain.
|
||||
batch_size : int, optional
|
||||
Number of training samples per batch.
|
||||
Number of training samples per batch. Defaults to 32.
|
||||
num_workers : int, optional
|
||||
Number of workers used for generating training samples.
|
||||
pin_memory : bool, optional
|
||||
If True, data loaders will copy tensors into CUDA pinned
|
||||
memory before returning them. See pytorch documentation
|
||||
for more details. Defaults to False.
|
||||
optimizer : callable, optional
|
||||
Callable that takes model parameters as input and returns
|
||||
an Optimizer instance. Defaults to `torch.optim.Adam`.
|
||||
learning_rate : float, optional
|
||||
Learning rate. Defaults to 1e-3.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@@ -82,9 +90,11 @@ class OverlappedSpeechDetection(SegmentationTaskMixin, Task):
|
||||
snr_min: float = 0.0,
|
||||
snr_max: float = 10.0,
|
||||
domain: str = None,
|
||||
batch_size: int = None,
|
||||
batch_size: int = 32,
|
||||
num_workers: int = 1,
|
||||
pin_memory: bool = False,
|
||||
optimizer: Callable[[Iterable[Parameter]], Optimizer] = None,
|
||||
learning_rate: float = 1e-3,
|
||||
):
|
||||
|
||||
super().__init__(
|
||||
@@ -93,6 +103,8 @@ class OverlappedSpeechDetection(SegmentationTaskMixin, Task):
|
||||
batch_size=batch_size,
|
||||
num_workers=num_workers,
|
||||
pin_memory=pin_memory,
|
||||
optimizer=optimizer,
|
||||
learning_rate=learning_rate,
|
||||
)
|
||||
|
||||
self.specifications = TaskSpecification(
|
||||
|
||||
@@ -20,8 +20,12 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
from typing import Callable, Iterable
|
||||
|
||||
import numpy as np
|
||||
import scipy.signal
|
||||
from torch.nn import Parameter
|
||||
from torch.optim import Optimizer
|
||||
|
||||
from pyannote.audio.core.task import Problem, Scale, Task, TaskSpecification
|
||||
from pyannote.audio.tasks.segmentation.mixins import SegmentationTaskMixin
|
||||
@@ -50,13 +54,18 @@ class SpeakerChangeDetection(SegmentationTaskMixin, Task):
|
||||
Mark frames less than `collar` frames away from actual change point as positive.
|
||||
Defaults to 1.
|
||||
batch_size : int, optional
|
||||
Number of training samples per batch.
|
||||
Number of training samples per batch. Defaults to 32.
|
||||
num_workers : int, optional
|
||||
Number of workers used for generating training samples.
|
||||
pin_memory : bool, optional
|
||||
If True, data loaders will copy tensors into CUDA pinned
|
||||
memory before returning them. See pytorch documentation
|
||||
for more details. Defaults to False.
|
||||
optimizer : callable, optional
|
||||
Callable that takes model parameters as input and returns
|
||||
an Optimizer instance. Defaults to `torch.optim.Adam`.
|
||||
learning_rate : float, optional
|
||||
Learning rate. Defaults to 1e-3.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@@ -64,9 +73,11 @@ class SpeakerChangeDetection(SegmentationTaskMixin, Task):
|
||||
protocol: Protocol,
|
||||
duration: float = 2.0,
|
||||
collar: int = 1,
|
||||
batch_size: int = None,
|
||||
batch_size: int = 32,
|
||||
num_workers: int = 1,
|
||||
pin_memory: bool = False,
|
||||
optimizer: Callable[[Iterable[Parameter]], Optimizer] = None,
|
||||
learning_rate: float = 1e-3,
|
||||
):
|
||||
|
||||
super().__init__(
|
||||
@@ -75,6 +86,8 @@ class SpeakerChangeDetection(SegmentationTaskMixin, Task):
|
||||
batch_size=batch_size,
|
||||
num_workers=num_workers,
|
||||
pin_memory=pin_memory,
|
||||
optimizer=optimizer,
|
||||
learning_rate=learning_rate,
|
||||
)
|
||||
|
||||
self.specifications = TaskSpecification(
|
||||
|
||||
@@ -20,7 +20,10 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
from typing import List, Text
|
||||
from typing import Callable, Iterable, List, Text
|
||||
|
||||
from torch.nn import Parameter
|
||||
from torch.optim import Optimizer
|
||||
|
||||
from pyannote.audio.core.task import Problem, Scale, Task, TaskSpecification
|
||||
from pyannote.audio.tasks.segmentation.mixins import SegmentationTaskMixin
|
||||
@@ -44,22 +47,29 @@ class SpeakerTracking(SegmentationTaskMixin, Task):
|
||||
duration : float, optional
|
||||
Chunks duration. Defaults to 2s.
|
||||
batch_size : int, optional
|
||||
Number of training samples per batch.
|
||||
Number of training samples per batch. Defaults to 32.
|
||||
num_workers : int, optional
|
||||
Number of workers used for generating training samples.
|
||||
pin_memory : bool, optional
|
||||
If True, data loaders will copy tensors into CUDA pinned
|
||||
memory before returning them. See pytorch documentation
|
||||
for more details. Defaults to False.
|
||||
optimizer : callable, optional
|
||||
Callable that takes model parameters as input and returns
|
||||
an Optimizer instance. Defaults to `torch.optim.Adam`.
|
||||
learning_rate : float, optional
|
||||
Learning rate. Defaults to 1e-3.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
protocol: Protocol,
|
||||
duration: float = 2.0,
|
||||
batch_size: int = None,
|
||||
batch_size: int = 32,
|
||||
num_workers: int = 1,
|
||||
pin_memory: bool = False,
|
||||
optimizer: Callable[[Iterable[Parameter]], Optimizer] = None,
|
||||
learning_rate: float = 1e-3,
|
||||
):
|
||||
|
||||
super().__init__(
|
||||
@@ -68,6 +78,8 @@ class SpeakerTracking(SegmentationTaskMixin, Task):
|
||||
batch_size=batch_size,
|
||||
num_workers=num_workers,
|
||||
pin_memory=pin_memory,
|
||||
optimizer=optimizer,
|
||||
learning_rate=learning_rate,
|
||||
)
|
||||
|
||||
# for speaker tracking, task specification depends
|
||||
|
||||
@@ -20,8 +20,11 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
from typing import Callable, Iterable
|
||||
|
||||
import numpy as np
|
||||
from torch.nn import Parameter
|
||||
from torch.optim import Optimizer
|
||||
|
||||
from pyannote.audio.core.task import Problem, Scale, Task, TaskSpecification
|
||||
from pyannote.audio.tasks.segmentation.mixins import SegmentationTaskMixin
|
||||
@@ -44,23 +47,29 @@ class VoiceActivityDetection(SegmentationTaskMixin, Task):
|
||||
duration : float, optional
|
||||
Chunks duration. Defaults to 2s.
|
||||
batch_size : int, optional
|
||||
Number of training samples per batch.
|
||||
Number of training samples per batch. Defaults to 32.
|
||||
num_workers : int, optional
|
||||
Number of workers used for generating training samples.
|
||||
pin_memory : bool, optional
|
||||
If True, data loaders will copy tensors into CUDA pinned
|
||||
memory before returning them. See pytorch documentation
|
||||
for more details. Defaults to False.
|
||||
|
||||
optimizer : callable, optional
|
||||
Callable that takes model parameters as input and returns
|
||||
an Optimizer instance. Defaults to `torch.optim.Adam`.
|
||||
learning_rate : float, optional
|
||||
Learning rate. Defaults to 1e-3.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
protocol: Protocol,
|
||||
duration: float = 2.0,
|
||||
batch_size: int = None,
|
||||
batch_size: int = 32,
|
||||
num_workers: int = 1,
|
||||
pin_memory: bool = False,
|
||||
optimizer: Callable[[Iterable[Parameter]], Optimizer] = None,
|
||||
learning_rate: float = 1e-3,
|
||||
):
|
||||
|
||||
super().__init__(
|
||||
@@ -69,6 +78,8 @@ class VoiceActivityDetection(SegmentationTaskMixin, Task):
|
||||
batch_size=batch_size,
|
||||
num_workers=num_workers,
|
||||
pin_memory=pin_memory,
|
||||
optimizer=optimizer,
|
||||
learning_rate=learning_rate,
|
||||
)
|
||||
|
||||
self.specifications = TaskSpecification(
|
||||
|
||||
@@ -20,12 +20,16 @@
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
from itertools import chain
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Callable, Iterable
|
||||
|
||||
import pytorch_metric_learning.losses
|
||||
import torch.optim
|
||||
from torch.nn import Parameter
|
||||
from torch.optim import Optimizer
|
||||
|
||||
from pyannote.audio.core.task import Problem, Scale, Task, TaskSpecification
|
||||
from pyannote.audio.utils.random import create_rng_for_worker
|
||||
@@ -44,6 +48,11 @@ class SpeakerEmbeddingArcFace(Task):
|
||||
If True, data loaders will copy tensors into CUDA pinned
|
||||
memory before returning them. See pytorch documentation
|
||||
for more details. Defaults to False.
|
||||
optimizer : callable, optional
|
||||
Callable that takes model parameters as input and returns
|
||||
an Optimizer instance. Defaults to `torch.optim.Adam`.
|
||||
learning_rate : float, optional
|
||||
Learning rate. Defaults to 1e-3.
|
||||
|
||||
|
||||
"""
|
||||
@@ -56,17 +65,27 @@ class SpeakerEmbeddingArcFace(Task):
|
||||
self,
|
||||
protocol: Protocol,
|
||||
duration: float = 2.0,
|
||||
batch_size: int = None,
|
||||
num_chunks_per_speaker: int = 1,
|
||||
num_speakers_per_batch: int = 32,
|
||||
num_workers: int = 1,
|
||||
pin_memory: bool = False,
|
||||
optimizer: Callable[[Iterable[Parameter]], Optimizer] = None,
|
||||
learning_rate: float = 1e-3,
|
||||
):
|
||||
|
||||
self.num_chunks_per_speaker = num_chunks_per_speaker
|
||||
self.num_speakers_per_batch = num_speakers_per_batch
|
||||
|
||||
batch_size = self.num_chunks_per_speaker * self.num_speakers_per_batch
|
||||
|
||||
super().__init__(
|
||||
protocol,
|
||||
duration=duration,
|
||||
batch_size=batch_size,
|
||||
num_workers=num_workers,
|
||||
pin_memory=pin_memory,
|
||||
optimizer=optimizer,
|
||||
learning_rate=learning_rate,
|
||||
)
|
||||
|
||||
# there is no such thing as a "class" in representation
|
||||
@@ -152,8 +171,8 @@ class SpeakerEmbeddingArcFace(Task):
|
||||
# speaker index in original sorted order
|
||||
y = self.specifications.classes.index(speaker)
|
||||
|
||||
# three chunks per speaker
|
||||
for _ in range(3):
|
||||
# multiple chunks per speaker
|
||||
for _ in range(self.num_chunks_per_speaker):
|
||||
|
||||
# select one file at random (with probability proportional to its speaker duration)
|
||||
file, *_ = rng.choices(
|
||||
@@ -199,6 +218,5 @@ class SpeakerEmbeddingArcFace(Task):
|
||||
def val_dataloader(self):
|
||||
return None
|
||||
|
||||
def configure_optimizers(self, model: "Model"):
|
||||
parameters = chain(model.parameters(), self.loss_func.parameters())
|
||||
return torch.optim.Adam(parameters, lr=1e-3)
|
||||
def parameters(self, model: Model) -> Iterable[Parameter]:
|
||||
return chain(model.parameters(), self.loss_func.parameters())
|
||||
@@ -1,4 +1,5 @@
|
||||
einops >= 0.3.0
|
||||
hydra-core >= 1.0.4
|
||||
librosa >= 0.8
|
||||
pyannote.core >= 4.1
|
||||
pyannote.database >= 4.0.3
|
||||
|
||||
@@ -50,20 +50,12 @@ dev =
|
||||
black>=19.10b0
|
||||
|
||||
[options.entry_points]
|
||||
# Add here console scripts like:
|
||||
# console_scripts =
|
||||
# script_name = fastaudio.module:function
|
||||
# For example:
|
||||
# console_scripts =
|
||||
# fibonacci = fastaudio.skeleton:run
|
||||
# And any other entry points, for example:
|
||||
|
||||
console_scripts =
|
||||
pyannote-audio-train=pyannote.audio.cli.train:main
|
||||
|
||||
# pyscaffold.cli =
|
||||
# awesome = pyscaffoldext.awesome.extension:AwesomeExtension
|
||||
|
||||
#console_scripts =
|
||||
# pyannote-audio=pyannote.audio.applications.pyannote_audio:main
|
||||
# pyannote-speech-feature=pyannote.audio.applications.feature_extraction:main
|
||||
|
||||
#prodigy_recipes =
|
||||
# pyannote.sad.manual = pyannote.audio.interactive.recipes.sad:sad_manual
|
||||
# pyannote.dia.binary = pyannote.audio.interactive.recipes.dia:dia_binary
|
||||
|
||||
Reference in new issue
Block a user