mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
fix(model): honor ToTaToNet linear hidden size (#2077)
Co-authored-by: Hervé BREDIN <hbredin@users.noreply.github.com>
This commit is contained in:
1 parent
6c96c5c6d0
commit
cc679dc7d6
3 files changed
+80
-1
No files matched your search
@@ -9,6 +9,7 @@
|
||||
Python 3.14's default on Linux, by warning and using `num_workers=0`
|
||||
|
||||
- fix(pipeline): omit unset `token` and `cache_dir` when expanding `$model/` references so loaders can inherit runtime options
|
||||
- fix(model): honor the configured linear hidden size in `ToTaToNet` [@antonsoo](https://github.com/antonsoo)
|
||||
- fix(io): fix `Audio.crop` raising when an in-memory waveform is cropped up to its very end [@MohammadHijjawi97](https://github.com/MohammadHijjawi97)
|
||||
- feat(cli): add `--subfolder` option to `benchmark` command [@antoinelaurent](https://github.com/antoinelaurent)
|
||||
- fix(utils): fix `SpeakerDiarizationMixin.optimal_mapping` `reference` is a mapping [@Kayvan-Zahiri](https://github.com/Kayvan-Zahiri)
|
||||
|
||||
@@ -233,7 +233,9 @@ class ToTaToNet(Model):
|
||||
|
||||
def build(self):
|
||||
if self.hparams.linear["num_layers"] > 0:
|
||||
self.classifier = nn.Linear(64, self.dimension)
|
||||
self.classifier = nn.Linear(
|
||||
self.hparams.linear["hidden_size"], self.dimension
|
||||
)
|
||||
else:
|
||||
self.classifier = nn.Linear(1, self.dimension)
|
||||
self.activation = self.default_activation()
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2024-2025 CNRS
|
||||
# Copyright (c) 2025- pyannoteAI
|
||||
#
|
||||
# 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.
|
||||
|
||||
|
||||
import pytest
|
||||
import torch
|
||||
|
||||
from pyannote.audio.core.task import Problem, Resolution, Specifications
|
||||
from pyannote.audio.models.separation.ToTaToNet import ToTaToNet
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"linear",
|
||||
[
|
||||
None,
|
||||
{"hidden_size": 8, "num_layers": 1},
|
||||
{"hidden_size": 96, "num_layers": 2},
|
||||
{"num_layers": 0},
|
||||
],
|
||||
ids=["default", "narrow", "wide", "no_hidden_layers"],
|
||||
)
|
||||
def test_totatonet_linear_configuration(linear):
|
||||
pytest.importorskip("asteroid")
|
||||
pytest.importorskip("transformers")
|
||||
model = ToTaToNet(
|
||||
use_wavlm=False,
|
||||
n_sources=2,
|
||||
linear=linear,
|
||||
encoder_decoder={"n_filters": 8},
|
||||
dprnn={"n_repeats": 1, "bn_chan": 8, "hid_size": 8, "chunk_size": 50},
|
||||
)
|
||||
model.specifications = (
|
||||
Specifications(
|
||||
problem=Problem.MULTI_LABEL_CLASSIFICATION,
|
||||
resolution=Resolution.FRAME,
|
||||
duration=2.0,
|
||||
classes=["speaker#1", "speaker#2"],
|
||||
),
|
||||
Specifications(
|
||||
problem=Problem.MONO_LABEL_CLASSIFICATION,
|
||||
resolution=Resolution.FRAME,
|
||||
duration=2.0,
|
||||
classes=["speaker#1", "speaker#2"],
|
||||
),
|
||||
)
|
||||
model.build()
|
||||
waveforms = torch.randn(2, 1, 32000)
|
||||
diarization, sources = model(waveforms)
|
||||
assert diarization.shape == (2, model.num_frames(32000), 2)
|
||||
assert sources.shape == (2, 32000, 2)
|
||||
assert torch.isfinite(diarization).all()
|
||||
assert torch.isfinite(sources).all()
|
||||
(diarization.square().mean() + sources.square().mean()).backward()
|
||||
assert model.classifier.weight.grad is not None
|
||||
assert torch.isfinite(model.classifier.weight.grad).all()
|
||||
assert torch.count_nonzero(model.classifier.weight.grad) > 0
|
||||
Reference in new issue
Block a user