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
20689b7f
"torchvision/git@developer.sourcefind.cn:OpenDAS/vision.git" did not exist on "97f543f3bc917ecaefb5b194f5cd7c342fbf78c9"
Unverified
Commit
20689b7f
authored
Apr 29, 2020
by
moto
Committed by
GitHub
Apr 29, 2020
Browse files
Add Kaldi compatibility tests for sliding_window_cmn (#560)
parent
9ceb96c0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
test/test_kaldi_compatibility.py
test/test_kaldi_compatibility.py
+53
-0
No files found.
test/test_kaldi_compatibility.py
0 → 100644
View file @
20689b7f
"""Test suites for checking numerical compatibility against Kaldi"""
import
shutil
import
unittest
import
subprocess
import
kaldi_io
import
torch
import
torchaudio.functional
as
F
def
_exe_exists
(
cmd
):
return
shutil
.
which
(
cmd
)
is
not
None
def
_convert_args
(
**
kwargs
):
args
=
[]
for
key
,
value
in
kwargs
.
items
():
key
=
'--'
+
key
.
replace
(
'_'
,
'-'
)
value
=
str
(
value
).
lower
()
if
value
in
[
True
,
False
]
else
str
(
value
)
args
.
append
(
'%s=%s'
%
(
key
,
value
))
return
args
def
_run_kaldi
(
command
,
input_tensor
):
"""Run provided Kaldi command, pass a tensor and get the resulting tensor
Assumption:
The provided Kaldi command consumes one ark and produces one ark.
i.e. 'ark:- ark:-'
"""
process
=
subprocess
.
Popen
(
command
,
stdin
=
subprocess
.
PIPE
,
stdout
=
subprocess
.
PIPE
)
kaldi_io
.
write_mat
(
process
.
stdin
,
input_tensor
.
numpy
(),
key
=
'foo'
)
process
.
stdin
.
close
()
result
=
dict
(
kaldi_io
.
read_mat_ark
(
process
.
stdout
))[
'foo'
]
return
torch
.
from_numpy
(
result
.
copy
())
# copy supresses some torch warning
class
TestFunctional
:
@
unittest
.
skipUnless
(
_exe_exists
(
'apply-cmvn-sliding'
),
'`apply-cmvn-sliding` not available'
)
def
test_sliding_window_cmn
(
self
):
"""sliding_window_cmn should be numerically compatible with apply-cmvn-sliding"""
kwargs
=
{
'cmn_window'
:
600
,
'min_cmn_window'
:
100
,
'center'
:
False
,
'norm_vars'
:
False
,
}
tensor
=
torch
.
randn
(
40
,
10
)
result
=
F
.
sliding_window_cmn
(
tensor
,
**
kwargs
)
command
=
[
'apply-cmvn-sliding'
]
+
_convert_args
(
**
kwargs
)
+
[
'ark:-'
,
'ark:-'
]
kaldi_result
=
_run_kaldi
(
command
,
tensor
)
torch
.
testing
.
assert_allclose
(
result
,
kaldi_result
)
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