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
d3f967e9
Unverified
Commit
d3f967e9
authored
Mar 10, 2020
by
Tomás Osório
Committed by
GitHub
Mar 10, 2020
Browse files
add batch test to TimeStretch (#459)
parent
9efc3503
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
test/test_transforms.py
test/test_transforms.py
+30
-0
No files found.
test/test_transforms.py
View file @
d3f967e9
...
@@ -519,6 +519,36 @@ class Tester(unittest.TestCase):
...
@@ -519,6 +519,36 @@ class Tester(unittest.TestCase):
tensor
=
torch
.
rand
((
10
,
2
,
n_freq
,
10
,
2
))
tensor
=
torch
.
rand
((
10
,
2
,
n_freq
,
10
,
2
))
_test_script_module
(
transforms
.
TimeStretch
,
tensor
,
n_freq
=
n_freq
,
hop_length
=
hop_length
,
fixed_rate
=
fixed_rate
)
_test_script_module
(
transforms
.
TimeStretch
,
tensor
,
n_freq
=
n_freq
,
hop_length
=
hop_length
,
fixed_rate
=
fixed_rate
)
def
test_batch_TimeStretch
(
self
):
waveform
,
sample_rate
=
torchaudio
.
load
(
self
.
test_filepath
)
kwargs
=
{
'n_fft'
:
2048
,
'hop_length'
:
512
,
'win_length'
:
2048
,
'window'
:
torch
.
hann_window
(
2048
),
'center'
:
True
,
'pad_mode'
:
'reflect'
,
'normalized'
:
True
,
'onesided'
:
True
,
}
rate
=
2
complex_specgrams
=
torch
.
stft
(
waveform
,
**
kwargs
)
# Single then transform then batch
expected
=
transforms
.
TimeStretch
(
fixed_rate
=
rate
,
n_freq
=
1025
,
hop_length
=
512
)(
complex_specgrams
).
repeat
(
3
,
1
,
1
,
1
,
1
)
# Batch then transform
computed
=
transforms
.
TimeStretch
(
fixed_rate
=
rate
,
n_freq
=
1025
,
hop_length
=
512
)(
complex_specgrams
.
repeat
(
3
,
1
,
1
,
1
,
1
))
self
.
assertTrue
(
computed
.
shape
==
expected
.
shape
,
(
computed
.
shape
,
expected
.
shape
))
self
.
assertTrue
(
torch
.
allclose
(
computed
,
expected
,
atol
=
1e-5
))
def
test_batch_Fade
(
self
):
def
test_batch_Fade
(
self
):
waveform
,
sample_rate
=
torchaudio
.
load
(
self
.
test_filepath
)
waveform
,
sample_rate
=
torchaudio
.
load
(
self
.
test_filepath
)
fade_in_len
=
3000
fade_in_len
=
3000
...
...
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