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
hehl2
Torchaudio
Commits
d1adb7f6
"torchvision/transforms/v2/_transform.py" did not exist on "f15ba56fec946e97a1f675e16e0c640a6284d337"
Unverified
Commit
d1adb7f6
authored
Apr 03, 2020
by
moto
Committed by
GitHub
Apr 03, 2020
Browse files
Enforce flake8 E841 and E821 (#504)
parent
7ef1178e
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
7 additions
and
26 deletions
+7
-26
.flake8
.flake8
+1
-1
test/test_batch_consistency.py
test/test_batch_consistency.py
+1
-1
test/test_functional_filtering.py
test/test_functional_filtering.py
+2
-7
test/test_sox_effects.py
test/test_sox_effects.py
+1
-1
test/test_transforms.py
test/test_transforms.py
+2
-2
torchaudio/functional.py
torchaudio/functional.py
+0
-14
No files found.
.flake8
View file @
d1adb7f6
[flake8]
max-line-length = 120
ignore = E305,E402,E721,E741,F401,F403,F405,
F821,F841,
F999,W503,W504
ignore = E305,E402,E721,E741,F401,F403,F405,F999,W503,W504
exclude = build,docs/source,_ext
test/test_batch_consistency.py
View file @
d1adb7f6
...
...
@@ -64,7 +64,7 @@ def _test_batch(functional, tensor, *args, **kwargs):
expected
=
expected
.
repeat
(
*
ind
)
torch
.
random
.
manual_seed
(
42
)
computed
=
functional
(
tensors
.
clone
(),
*
args
,
**
kwargs
)
_
=
functional
(
tensors
.
clone
(),
*
args
,
**
kwargs
)
class
TestFunctional
(
unittest
.
TestCase
):
...
...
test/test_functional_filtering.py
View file @
d1adb7f6
import
os
import
time
import
unittest
import
torch
...
...
@@ -450,17 +449,13 @@ class TestFunctionalFiltering(unittest.TestCase):
# SoX method
E
=
torchaudio
.
sox_effects
.
SoxEffectsChain
()
E
.
set_input_file
(
fn_sine
)
_timing_sox
=
time
.
time
()
E
.
append_effect_to_chain
(
"biquad"
,
[
b0
,
b1
,
b2
,
a0
,
a1
,
a2
])
waveform_sox_out
,
sr
=
E
.
sox_build_flow_effects
()
_timing_sox_run_time
=
time
.
time
()
-
_timing_sox
waveform_sox_out
,
_
=
E
.
sox_build_flow_effects
()
_timing_lfilter_filtering
=
time
.
time
()
waveform
,
sample_rate
=
torchaudio
.
load
(
fn_sine
,
normalization
=
True
)
waveform
,
_
=
torchaudio
.
load
(
fn_sine
,
normalization
=
True
)
waveform_lfilter_out
=
F
.
lfilter
(
waveform
,
torch
.
tensor
([
a0
,
a1
,
a2
]),
torch
.
tensor
([
b0
,
b1
,
b2
])
)
_timing_lfilter_run_time
=
time
.
time
()
-
_timing_lfilter_filtering
assert
torch
.
allclose
(
waveform_sox_out
,
waveform_lfilter_out
,
atol
=
1e-4
)
_test_torchscript_functional
(
...
...
test/test_sox_effects.py
View file @
d1adb7f6
...
...
@@ -257,7 +257,7 @@ class Test_SoxEffectsChain(unittest.TestCase):
vol
=
torchaudio
.
transforms
.
Vol
(
gain
,
gain_type
)
z
=
vol
(
x_orig
)
# check if effect worked
self
.
assertTrue
(
x
.
allclose
(
vol
(
x_orig
)
,
rtol
=
1e-4
,
atol
=
1e-4
))
self
.
assertTrue
(
x
.
allclose
(
z
,
rtol
=
1e-4
,
atol
=
1e-4
))
if
__name__
==
'__main__'
:
...
...
test/test_transforms.py
View file @
d1adb7f6
...
...
@@ -212,7 +212,7 @@ class Tester(unittest.TestCase):
def
test_compute_deltas_twochannel
(
self
):
specgram
=
torch
.
tensor
([
1.
,
2.
,
3.
,
4.
]).
repeat
(
1
,
2
,
1
)
expected
=
torch
.
tensor
([[[
0.5
,
1.0
,
1.0
,
0.5
],
_
=
torch
.
tensor
([[[
0.5
,
1.0
,
1.0
,
0.5
],
[
0.5
,
1.0
,
1.0
,
0.5
]]])
transform
=
transforms
.
ComputeDeltas
()
computed
=
transform
(
specgram
)
...
...
torchaudio/functional.py
View file @
d1adb7f6
...
...
@@ -463,8 +463,6 @@ def create_fb_matrix(
# freq bins
# Equivalent filterbank construction by Librosa
all_freqs
=
torch
.
linspace
(
0
,
sample_rate
//
2
,
n_freqs
)
i_freqs
=
all_freqs
.
ge
(
f_min
)
&
all_freqs
.
le
(
f_max
)
freqs
=
all_freqs
[
i_freqs
]
# calculate mel freq bins
# hertz to mel(f) is 2595. * math.log10(1. + (f / 700.))
...
...
@@ -710,9 +708,6 @@ def lfilter(
Returns:
Tensor: Waveform with dimension of `(..., time)`. Output will be clipped to -1 to 1.
"""
dim
=
waveform
.
dim
()
# pack batch
shape
=
waveform
.
size
()
waveform
=
waveform
.
view
(
-
1
,
shape
[
-
1
])
...
...
@@ -820,12 +815,8 @@ def highpass_biquad(
Returns:
Tensor: Waveform dimension of `(..., time)`
"""
GAIN
=
1.
w0
=
2
*
math
.
pi
*
cutoff_freq
/
sample_rate
A
=
math
.
exp
(
GAIN
/
40.0
*
math
.
log
(
10
))
alpha
=
math
.
sin
(
w0
)
/
2.
/
Q
mult
=
_dB2Linear
(
max
(
GAIN
,
0
))
b0
=
(
1
+
math
.
cos
(
w0
))
/
2
b1
=
-
1
-
math
.
cos
(
w0
)
...
...
@@ -853,12 +844,8 @@ def lowpass_biquad(
Returns:
Tensor: Waveform of dimension of `(..., time)`
"""
GAIN
=
1.
w0
=
2
*
math
.
pi
*
cutoff_freq
/
sample_rate
A
=
math
.
exp
(
GAIN
/
40.0
*
math
.
log
(
10
))
alpha
=
math
.
sin
(
w0
)
/
2
/
Q
mult
=
_dB2Linear
(
max
(
GAIN
,
0
))
b0
=
(
1
-
math
.
cos
(
w0
))
/
2
b1
=
1
-
math
.
cos
(
w0
)
...
...
@@ -1030,7 +1017,6 @@ def band_biquad(
https://www.w3.org/2011/audio/audio-eq-cookbook.html#APF
"""
w0
=
2
*
math
.
pi
*
central_freq
/
sample_rate
alpha
=
math
.
sin
(
w0
)
/
2
/
Q
bw_Hz
=
central_freq
/
Q
a0
=
1.
...
...
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