From 3d5f934584faad54dcd657ef0e0bb3665efa66be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Schw=C3=A4r?= Date: Fri, 9 Feb 2024 13:04:24 +0100 Subject: [PATCH] Change magnitude calculation in STFTLoss for better interpretability of the eps parameter Previously, small values were clamped inside a `torch.sqrt`, so that the smallest possible values were sqrt(eps) instead of eps. For example, the default eps=1e-8 led to a smallest value of 1e-4. --- auraloss/freq.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/auraloss/freq.py b/auraloss/freq.py index a5efe70..4393468 100644 --- a/auraloss/freq.py +++ b/auraloss/freq.py @@ -200,9 +200,7 @@ def stft(self, x): self.window, return_complex=True, ) - x_mag = torch.sqrt( - torch.clamp((x_stft.real**2) + (x_stft.imag**2), min=self.eps) - ) + x_mag = torch.clamp(torch.abs(x_stft), min=self.eps) x_phs = torch.angle(x_stft) return x_mag, x_phs