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
e061b268
Unverified
Commit
e061b268
authored
Apr 16, 2021
by
discort
Committed by
GitHub
Apr 15, 2021
Browse files
Use torchaudio melscale 'slaney' instead of librosa in WaveRNN pipeline preprocessing (#1444)
* Use torchaudio melscale instead of librosa
parent
48630302
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
31 deletions
+6
-31
examples/pipeline_wavernn/main.py
examples/pipeline_wavernn/main.py
+5
-5
examples/pipeline_wavernn/processing.py
examples/pipeline_wavernn/processing.py
+1
-26
No files found.
examples/pipeline_wavernn/main.py
View file @
e061b268
...
...
@@ -17,7 +17,7 @@ from torchaudio.models.wavernn import WaveRNN
from
datasets
import
collate_factory
,
split_process_dataset
from
losses
import
LongCrossEntropyLoss
,
MoLLoss
from
processing
import
LinearToMel
,
NormalizeDB
from
processing
import
NormalizeDB
from
utils
import
MetricLogger
,
count_parameters
,
save_checkpoint
...
...
@@ -269,12 +269,12 @@ def main(args):
}
transforms
=
torch
.
nn
.
Sequential
(
torchaudio
.
transforms
.
Spectrogram
(
**
melkwargs
),
LinearToMel
(
torchaudio
.
transforms
.
MelSpectrogram
(
sample_rate
=
args
.
sample_rate
,
n_fft
=
args
.
n_fft
,
n_mels
=
args
.
n_freq
,
fmin
=
args
.
f_min
,
f_min
=
args
.
f_min
,
mel_scale
=
'slaney'
,
**
melkwargs
,
),
NormalizeDB
(
min_level_db
=
args
.
min_level_db
,
normalization
=
args
.
normalization
),
)
...
...
examples/pipeline_wavernn/processing.py
View file @
e061b268
import
librosa
import
torch
import
torch.nn
as
nn
# TODO Replace by torchaudio, once https://github.com/pytorch/audio/pull/593 is resolved
class
LinearToMel
(
nn
.
Module
):
def
__init__
(
self
,
sample_rate
,
n_fft
,
n_mels
,
fmin
,
htk
=
False
,
norm
=
"slaney"
):
super
().
__init__
()
self
.
sample_rate
=
sample_rate
self
.
n_fft
=
n_fft
self
.
n_mels
=
n_mels
self
.
fmin
=
fmin
self
.
htk
=
htk
self
.
norm
=
norm
def
forward
(
self
,
specgram
):
specgram
=
librosa
.
feature
.
melspectrogram
(
S
=
specgram
.
squeeze
(
0
).
numpy
(),
sr
=
self
.
sample_rate
,
n_fft
=
self
.
n_fft
,
n_mels
=
self
.
n_mels
,
fmin
=
self
.
fmin
,
htk
=
self
.
htk
,
norm
=
self
.
norm
,
)
return
torch
.
from_numpy
(
specgram
)
class
NormalizeDB
(
nn
.
Module
):
r
"""Normalize the spectrogram with a minimum db value
"""
...
...
@@ -37,7 +12,7 @@ class NormalizeDB(nn.Module):
self
.
normalization
=
normalization
def
forward
(
self
,
specgram
):
specgram
=
torch
.
log10
(
torch
.
clamp
(
specgram
,
min
=
1e-5
))
specgram
=
torch
.
log10
(
torch
.
clamp
(
specgram
.
squeeze
(
0
)
,
min
=
1e-5
))
if
self
.
normalization
:
return
torch
.
clamp
(
(
self
.
min_level_db
-
20
*
specgram
)
/
self
.
min_level_db
,
min
=
0
,
max
=
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