Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return dtype in MVDR module #2376

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions test/torchaudio_unittest/transforms/transforms_test_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,28 @@ def test_psd(self, duration, channel, mask, multi_mask):
psd_np = psd_numpy(spectrogram.detach().numpy(), mask, multi_mask)
psd = transform(spectrogram, mask)
self.assertEqual(psd, psd_np, atol=1e-5, rtol=1e-5)

@parameterized.expand(
[
param("ref_channel", True, torch.complex64),
param("ref_channel", False, torch.complex128),
param("stv_evd", True, torch.complex128),
param("stv_evd", False, torch.complex64),
param("stv_power", True, torch.complex64),
param("stv_power", False, torch.complex128),
]
nateanl marked this conversation as resolved.
Show resolved Hide resolved
)
def test_mvdr(self, solution, multi_mask, dtype):
"""Make sure the output dtype is the same as the input dtype"""
transform = T.MVDR(solution=solution, multi_mask=multi_mask)
waveform = get_whitenoise(sample_rate=8000, duration=0.5, n_channels=3)
specgram = get_spectrogram(waveform, n_fft=400) # (channel, freq, time)
specgram = specgram.to(dtype)
if multi_mask:
mask_s = torch.rand(specgram.shape[-3:])
mask_n = torch.rand(specgram.shape[-3:])
else:
mask_s = torch.rand(specgram.shape[-2:])
mask_n = torch.rand(specgram.shape[-2:])
specgram_enhanced = transform(specgram, mask_s, mask_n)
assert specgram_enhanced.dtype == dtype
3 changes: 1 addition & 2 deletions torchaudio/transforms/_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2087,8 +2087,7 @@ def forward(
# unpack batch
specgram_enhanced = specgram_enhanced.reshape(shape[:-3] + shape[-2:])

specgram_enhanced.to(dtype)
return specgram_enhanced
return specgram_enhanced.to(dtype)


class RTFMVDR(torch.nn.Module):
Expand Down