Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
Torchaudio
Commits
264ab15a
Unverified
Commit
264ab15a
authored
May 19, 2021
by
Brian White
Committed by
GitHub
May 19, 2021
Browse files
Add deprecation warning to MelScale for unset weight (#1515)
parent
02589246
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
1 deletion
+28
-1
test/torchaudio_unittest/transforms/transforms_test_impl.py
test/torchaudio_unittest/transforms/transforms_test_impl.py
+19
-1
torchaudio/transforms.py
torchaudio/transforms.py
+9
-0
No files found.
test/torchaudio_unittest/transforms/transforms_test_impl.py
View file @
264ab15a
import
warnings
import
torch
import
torch
import
torchaudio.transforms
as
T
import
torchaudio.transforms
as
T
...
@@ -39,7 +41,7 @@ class TransformsTestBase(TestBaseMixin):
...
@@ -39,7 +41,7 @@ class TransformsTestBase(TestBaseMixin):
get_whitenoise
(
sample_rate
=
sample_rate
,
duration
=
1
,
n_channels
=
2
),
get_whitenoise
(
sample_rate
=
sample_rate
,
duration
=
1
,
n_channels
=
2
),
n_fft
=
n_fft
,
power
=
power
).
to
(
self
.
device
,
self
.
dtype
)
n_fft
=
n_fft
,
power
=
power
).
to
(
self
.
device
,
self
.
dtype
)
input
=
T
.
MelScale
(
input
=
T
.
MelScale
(
n_mels
=
n_mels
,
sample_rate
=
sample_rate
n_mels
=
n_mels
,
sample_rate
=
sample_rate
,
n_stft
=
n_stft
).
to
(
self
.
device
,
self
.
dtype
)(
expected
)
).
to
(
self
.
device
,
self
.
dtype
)(
expected
)
# Run transform
# Run transform
...
@@ -59,3 +61,19 @@ class TransformsTestBase(TestBaseMixin):
...
@@ -59,3 +61,19 @@ class TransformsTestBase(TestBaseMixin):
assert
_get_ratio
(
relative_diff
<
1e-1
)
>
0.2
assert
_get_ratio
(
relative_diff
<
1e-1
)
>
0.2
assert
_get_ratio
(
relative_diff
<
1e-3
)
>
5e-3
assert
_get_ratio
(
relative_diff
<
1e-3
)
>
5e-3
assert
_get_ratio
(
relative_diff
<
1e-5
)
>
1e-5
assert
_get_ratio
(
relative_diff
<
1e-5
)
>
1e-5
def
test_melscale_unset_weight_warning
(
self
):
"""Issue a warning if MelScale initialized without a weight
As part of the deprecation of lazy intialization behavior (#1510),
issue a warning if `n_stft` is not set.
"""
with
warnings
.
catch_warnings
(
record
=
True
)
as
caught_warnings
:
warnings
.
simplefilter
(
"always"
)
T
.
MelScale
(
n_mels
=
64
,
sample_rate
=
8000
)
assert
len
(
caught_warnings
)
==
1
with
warnings
.
catch_warnings
(
record
=
True
)
as
caught_warnings
:
warnings
.
simplefilter
(
"always"
)
T
.
MelScale
(
n_mels
=
64
,
sample_rate
=
8000
,
n_stft
=
201
)
assert
len
(
caught_warnings
)
==
0
torchaudio/transforms.py
View file @
264ab15a
...
@@ -283,6 +283,15 @@ class MelScale(torch.nn.Module):
...
@@ -283,6 +283,15 @@ class MelScale(torch.nn.Module):
assert
f_min
<=
self
.
f_max
,
'Require f_min: {} < f_max: {}'
.
format
(
f_min
,
self
.
f_max
)
assert
f_min
<=
self
.
f_max
,
'Require f_min: {} < f_max: {}'
.
format
(
f_min
,
self
.
f_max
)
if
n_stft
is
None
or
n_stft
==
0
:
warnings
.
warn
(
'Initialization of torchaudio.transforms.MelScale with an unset weight '
'`n_stft=None` is deprecated and will be removed from a future release. '
'Please set a proper `n_stft` value. Typically this is `n_fft // 2 + 1`. '
'Refer to https://github.com/pytorch/audio/issues/1510 '
'for more details.'
)
fb
=
torch
.
empty
(
0
)
if
n_stft
is
None
else
F
.
create_fb_matrix
(
fb
=
torch
.
empty
(
0
)
if
n_stft
is
None
else
F
.
create_fb_matrix
(
n_stft
,
self
.
f_min
,
self
.
f_max
,
self
.
n_mels
,
self
.
sample_rate
,
self
.
norm
,
n_stft
,
self
.
f_min
,
self
.
f_max
,
self
.
n_mels
,
self
.
sample_rate
,
self
.
norm
,
self
.
mel_scale
)
self
.
mel_scale
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment