mirror of
https://github.com/pyannote/pyannote-audio.git
synced 2026-11-20 13:07:51 +09:00
* feat(cli): add --subfolder option to benchmark command (#2063) * fix(utils): fix `SpeakerDiarizationMixin.optimal_mapping` when `reference` is a mapping * fix(task): fix `balance` option crashing training with `KeyError: 'metadata'` (#2067) * fix(io): fix `Audio.crop` raising when an in-memory waveform is cropped up to its very end (#2068) * fix(model): make Model.default_activation return identity for unsupported tasks * fix: compute sample duration from preloaded waveform * fix(pipeline): omit unset runtime options from model references (#2080) Co-authored-by: abeeranajam31 <128603901+abeeranajam31@users.noreply.github.com> Co-authored-by: antoinelaurent <antoinelaurent@me.com> Co-authored-by: Kayvan Zahiri <123409429+Kayvan-Zahiri@users.noreply.github.com> Co-authored-by: Mohammad Hijjawi <51020382+MohammadHijjawi97@users.noreply.github.com>
79 lines
1.5 KiB
Python
79 lines
1.5 KiB
Python
import torch
|
|
from torch import nn
|
|
|
|
from pyannote.audio.utils.probe import probe
|
|
|
|
|
|
class Trunk(nn.Module):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.layer1 = nn.Linear(1, 2)
|
|
self.layer2 = nn.Linear(2, 3)
|
|
self.layer3 = nn.Linear(3, 4)
|
|
|
|
def forward(self, x):
|
|
return self.layer3(self.layer2(self.layer1(x)))
|
|
|
|
|
|
def test_probe_dict():
|
|
trunk = Trunk()
|
|
probe(trunk, {"probe1": "layer1"})
|
|
out = trunk(
|
|
torch.ones(
|
|
1,
|
|
)
|
|
)
|
|
assert isinstance(out, dict)
|
|
assert len(out.keys()) == 1
|
|
assert isinstance(out["probe1"], torch.Tensor)
|
|
|
|
|
|
def test_probe_output():
|
|
trunk = Trunk()
|
|
probe(trunk, {"probe1": "layer3"})
|
|
out = trunk(
|
|
torch.ones(
|
|
1,
|
|
)
|
|
)
|
|
out = out["probe1"]
|
|
tout = trunk.layer3(
|
|
trunk.layer2(
|
|
trunk.layer1(
|
|
torch.ones(
|
|
1,
|
|
)
|
|
)
|
|
)
|
|
)
|
|
assert torch.equal(tout, out)
|
|
|
|
|
|
def test_probe_revert():
|
|
trunk = Trunk()
|
|
revert = probe(trunk, {"probe1": "layer3"})
|
|
out = trunk(
|
|
torch.ones(
|
|
1,
|
|
)
|
|
)
|
|
assert isinstance(out, dict)
|
|
revert()
|
|
out = trunk(
|
|
torch.ones(
|
|
1,
|
|
)
|
|
)
|
|
assert isinstance(out, torch.Tensor)
|
|
|
|
|
|
def test_probe_array():
|
|
trunk = Trunk()
|
|
probe(trunk, ["layer3"])
|
|
out = trunk(
|
|
torch.ones(
|
|
1,
|
|
)
|
|
)
|
|
assert isinstance(out, dict)
|