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
e868060d
Commit
e868060d
authored
Feb 11, 2019
by
David Pollack
Committed by
Soumith Chintala
Feb 12, 2019
Browse files
add friendly deprecation message (#81)
parent
7e15d2f9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
test/test_transforms.py
test/test_transforms.py
+2
-1
torchaudio/transforms.py
torchaudio/transforms.py
+28
-1
No files found.
test/test_transforms.py
View file @
e868060d
...
@@ -150,7 +150,8 @@ class Tester(unittest.TestCase):
...
@@ -150,7 +150,8 @@ class Tester(unittest.TestCase):
self
.
assertTrue
(
mel_transform
.
fm
.
fb
.
sum
(
1
).
le
(
1.
).
all
())
self
.
assertTrue
(
mel_transform
.
fm
.
fb
.
sum
(
1
).
le
(
1.
).
all
())
self
.
assertTrue
(
mel_transform
.
fm
.
fb
.
sum
(
1
).
ge
(
0.
).
all
())
self
.
assertTrue
(
mel_transform
.
fm
.
fb
.
sum
(
1
).
ge
(
0.
).
all
())
# check options
# check options
mel_transform2
=
transforms
.
MelSpectrogram
(
window
=
torch
.
hamming_window
,
pad
=
10
,
ws
=
500
,
hop
=
125
,
n_fft
=
800
,
n_mels
=
50
)
kwargs
=
{
"window"
:
torch
.
hamming_window
,
"pad"
:
10
,
"ws"
:
500
,
"hop"
:
125
,
"n_fft"
:
800
,
"n_mels"
:
50
}
mel_transform2
=
transforms
.
MelSpectrogram
(
**
kwargs
)
spectrogram2_torch
=
mel_transform2
(
audio_scaled
)
# (1, 506, 50)
spectrogram2_torch
=
mel_transform2
(
audio_scaled
)
# (1, 506, 50)
self
.
assertTrue
(
spectrogram2_torch
.
dim
()
==
3
)
self
.
assertTrue
(
spectrogram2_torch
.
dim
()
==
3
)
self
.
assertTrue
(
spectrogram2_torch
.
le
(
0.
).
all
())
self
.
assertTrue
(
spectrogram2_torch
.
le
(
0.
).
all
())
...
...
torchaudio/transforms.py
View file @
e868060d
from
__future__
import
division
,
print_function
from
__future__
import
division
,
print_function
from
warnings
import
warn
import
torch
import
torch
import
numpy
as
np
import
numpy
as
np
class
Compose
(
object
):
class
Compose
(
object
):
"""Composes several transforms together.
"""Composes several transforms together.
...
@@ -150,6 +152,11 @@ class LC2CL(object):
...
@@ -150,6 +152,11 @@ class LC2CL(object):
return
self
.
__class__
.
__name__
+
'()'
return
self
.
__class__
.
__name__
+
'()'
def
SPECTROGRAM
(
*
args
,
**
kwargs
):
warn
(
"SPECTROGRAM has been renamed to Spectrogram"
)
return
Spectrogram
(
*
args
,
**
kwargs
)
class
Spectrogram
(
object
):
class
Spectrogram
(
object
):
"""Create a spectrogram from a raw audio signal
"""Create a spectrogram from a raw audio signal
...
@@ -200,6 +207,11 @@ class Spectrogram(object):
...
@@ -200,6 +207,11 @@ class Spectrogram(object):
return
spec_f
return
spec_f
def
F2M
(
*
args
,
**
kwargs
):
warn
(
"F2M has been renamed to MelScale"
)
return
MelScale
(
*
args
,
**
kwargs
)
class
MelScale
(
object
):
class
MelScale
(
object
):
"""This turns a normal STFT into a mel frequency STFT, using a conversion
"""This turns a normal STFT into a mel frequency STFT, using a conversion
matrix. This uses triangular filter banks.
matrix. This uses triangular filter banks.
...
@@ -256,6 +268,11 @@ class MelScale(object):
...
@@ -256,6 +268,11 @@ class MelScale(object):
return
700.
*
(
10
**
(
mel
/
2595.
)
-
1.
)
return
700.
*
(
10
**
(
mel
/
2595.
)
-
1.
)
def
SPEC2DB
(
*
args
,
**
kwargs
):
warn
(
"SPEC2DB has been renamed to SpectogramToDB, please update your program"
)
return
SpectogramToDB
(
*
args
,
**
kwargs
)
class
SpectogramToDB
(
object
):
class
SpectogramToDB
(
object
):
"""Turns a spectrogram from the power/amplitude scale to the decibel scale.
"""Turns a spectrogram from the power/amplitude scale to the decibel scale.
...
@@ -276,10 +293,15 @@ class SpectogramToDB(object):
...
@@ -276,10 +293,15 @@ class SpectogramToDB(object):
spec_db
=
self
.
multiplier
*
torch
.
log10
(
spec
/
spec
.
max
())
# power -> dB
spec_db
=
self
.
multiplier
*
torch
.
log10
(
spec
/
spec
.
max
())
# power -> dB
if
self
.
top_db
is
not
None
:
if
self
.
top_db
is
not
None
:
spec_db
=
torch
.
max
(
spec_db
,
spec_db
.
new_full
((
1
,),
self
.
top_db
))
spec_db
=
torch
.
max
(
spec_db
,
spec_db
.
new_full
((
1
,),
self
.
top_db
))
return
spec_db
return
spec_db
def
MEL2
(
*
args
,
**
kwargs
):
warn
(
"MEL2 has been renamed to MelSpectrogram"
)
return
MelSpectrogram
(
*
args
,
**
kwargs
)
class
MelSpectrogram
(
object
):
class
MelSpectrogram
(
object
):
"""Create MEL Spectrograms from a raw audio signal using the stft
"""Create MEL Spectrograms from a raw audio signal using the stft
function in PyTorch.
function in PyTorch.
...
@@ -341,6 +363,11 @@ class MelSpectrogram(object):
...
@@ -341,6 +363,11 @@ class MelSpectrogram(object):
return
spec_mel_db
return
spec_mel_db
def
MEL
(
*
args
,
**
kwargs
):
raise
DeprecationWarning
(
"MEL has been removed from the library please use MelSpectrogram or librosa"
)
class
BLC2CBL
(
object
):
class
BLC2CBL
(
object
):
"""Permute a 3d tensor from Bands x Sample length x Channels to Channels x
"""Permute a 3d tensor from Bands x Sample length x Channels to Channels x
Bands x Samples length
Bands x Samples length
...
...
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