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
f1a9f79d
Unverified
Commit
f1a9f79d
authored
Sep 23, 2023
by
moto
Committed by
GitHub
Sep 23, 2023
Browse files
Refactor PRA test (#3616)
parent
0a27bb0d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
95 additions
and
97 deletions
+95
-97
test/torchaudio_unittest/prototype/functional/functional_cpu_test.py
...udio_unittest/prototype/functional/functional_cpu_test.py
+1
-11
test/torchaudio_unittest/prototype/functional/functional_test_impl.py
...dio_unittest/prototype/functional/functional_test_impl.py
+1
-86
test/torchaudio_unittest/prototype/functional/pyroomacoustics_compatibility_test.py
...rototype/functional/pyroomacoustics_compatibility_test.py
+93
-0
No files found.
test/torchaudio_unittest/prototype/functional/functional_cpu_test.py
View file @
f1a9f79d
import
torch
from
torchaudio_unittest.common_utils
import
PytorchTestCase
from
.functional_test_impl
import
Functional64OnlyTestImpl
,
FunctionalCPUOnlyTestImpl
,
FunctionalTestImpl
from
.functional_test_impl
import
Functional64OnlyTestImpl
,
FunctionalTestImpl
class
FunctionalFloat32CPUTest
(
FunctionalTestImpl
,
PytorchTestCase
):
...
...
@@ -17,13 +17,3 @@ class FunctionalFloat64CPUTest(FunctionalTestImpl, PytorchTestCase):
class
FunctionalFloat64OnlyCPUTest
(
Functional64OnlyTestImpl
,
PytorchTestCase
):
dtype
=
torch
.
float64
device
=
torch
.
device
(
"cpu"
)
class
FunctionalCPUOnlyFloat32Test
(
FunctionalCPUOnlyTestImpl
,
PytorchTestCase
):
dtype
=
torch
.
float32
device
=
torch
.
device
(
"cpu"
)
class
FunctionalCPUOnlyFloat64Test
(
FunctionalCPUOnlyTestImpl
,
PytorchTestCase
):
dtype
=
torch
.
float64
device
=
torch
.
device
(
"cpu"
)
test/torchaudio_unittest/prototype/functional/functional_test_impl.py
View file @
f1a9f79d
from
torchaudio._internal
import
module_utils
as
_mod_utils
if
_mod_utils
.
is_module_available
(
"pyroomacoustics"
):
import
pyroomacoustics
as
pra
import
torch
import
torchaudio.prototype.functional
as
F
from
parameterized
import
param
,
parameterized
from
torchaudio_unittest.common_utils
import
nested_params
,
skipIfNoModule
,
skipIfNoRIR
,
TestBaseMixin
from
torchaudio_unittest.common_utils
import
nested_params
,
TestBaseMixin
from
.dsp_utils
import
(
exp_sigmoid
as
exp_sigmoid_np
,
...
...
@@ -465,83 +460,3 @@ class Functional64OnlyTestImpl(TestBaseMixin):
except
AssertionError
:
_debug_plot
()
raise
@
skipIfNoModule
(
"pyroomacoustics"
)
@
skipIfNoRIR
class
FunctionalCPUOnlyTestImpl
(
TestBaseMixin
):
@
parameterized
.
expand
([(
1
,),
(
4
,)])
def
test_simulate_rir_ism_single_band
(
self
,
channel
):
"""Test simulate_rir_ism function in the case where absorption coefficients are identical for all walls."""
room_dim
=
torch
.
rand
(
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
5
mic_array
=
torch
.
rand
(
channel
,
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
1
source
=
torch
.
rand
(
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
4
max_order
=
3
# absorption is set as a float value indicating absorption coefficients are the same for every wall.
absorption
=
0.5
# compute rir signal by torchaudio implementation
actual
=
F
.
simulate_rir_ism
(
room_dim
,
source
,
mic_array
,
max_order
,
absorption
)
# compute rir signal by pyroomacoustics
room
=
pra
.
ShoeBox
(
room_dim
.
detach
().
numpy
(),
fs
=
16000
,
materials
=
pra
.
Material
(
absorption
),
max_order
=
max_order
,
ray_tracing
=
False
,
air_absorption
=
False
,
)
# mic_locs is a numpy array of dimension `(3, channel)`.
mic_locs
=
mic_array
.
transpose
(
0
,
1
).
double
().
detach
().
numpy
()
room
.
add_microphone_array
(
mic_locs
)
room
.
add_source
(
source
.
tolist
())
room
.
compute_rir
()
max_len
=
max
([
room
.
rir
[
i
][
0
].
shape
[
0
]
for
i
in
range
(
channel
)])
expected
=
torch
.
zeros
(
channel
,
max_len
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
for
i
in
range
(
channel
):
expected
[
i
,
0
:
room
.
rir
[
i
][
0
].
shape
[
0
]]
=
torch
.
from_numpy
(
room
.
rir
[
i
][
0
])
self
.
assertEqual
(
expected
,
actual
,
atol
=
1e-3
,
rtol
=
1e-3
)
@
parameterized
.
expand
([(
1
,),
(
4
,)])
def
test_simulate_rir_ism_multi_band
(
self
,
channel
):
"""Test simulate_rir_ism in the case where absorption coefficients are different for all walls."""
room_dim
=
torch
.
rand
(
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
5
mic_array
=
torch
.
rand
(
channel
,
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
1
source
=
torch
.
rand
(
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
4
max_order
=
3
# absorption is set as a Tensor with dimensions `(7, 6)` indicating there are
# 6 walls and each wall has 7 absorption coefficients corresponds to 7 octave bands, respectively.
absorption
=
torch
.
rand
(
7
,
6
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
walls
=
[
"west"
,
"east"
,
"south"
,
"north"
,
"floor"
,
"ceiling"
]
room
=
pra
.
ShoeBox
(
room_dim
.
detach
().
numpy
(),
fs
=
16000
,
materials
=
{
walls
[
i
]:
pra
.
Material
(
{
"coeffs"
:
absorption
[:,
i
]
.
reshape
(
-
1
,
)
.
detach
()
.
numpy
(),
"center_freqs"
:
[
125.0
,
250.0
,
500.0
,
1000.0
,
2000.0
,
4000.0
,
8000.0
],
}
)
for
i
in
range
(
len
(
walls
))
},
max_order
=
max_order
,
ray_tracing
=
False
,
air_absorption
=
False
,
)
# mic_locs is a numpy array of dimension `(D, channel)`.
mic_locs
=
mic_array
.
transpose
(
0
,
1
).
double
().
detach
().
numpy
()
room
.
add_microphone_array
(
mic_locs
)
room
.
add_source
(
source
.
tolist
())
room
.
compute_rir
()
max_len
=
max
([
room
.
rir
[
i
][
0
].
shape
[
0
]
for
i
in
range
(
channel
)])
expected
=
torch
.
zeros
(
channel
,
max_len
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
for
i
in
range
(
channel
):
expected
[
i
,
0
:
room
.
rir
[
i
][
0
].
shape
[
0
]]
=
torch
.
from_numpy
(
room
.
rir
[
i
][
0
])
actual
=
F
.
simulate_rir_ism
(
room_dim
,
source
,
mic_array
,
max_order
,
absorption
)
self
.
assertEqual
(
expected
,
actual
,
atol
=
1e-3
,
rtol
=
1e-3
)
test/torchaudio_unittest/prototype/functional/pyroomacoustics_compatibility_test.py
0 → 100644
View file @
f1a9f79d
import
torch
import
torchaudio.prototype.functional
as
F
from
parameterized
import
parameterized
from
torchaudio._internal
import
module_utils
as
_mod_utils
from
torchaudio_unittest.common_utils
import
PytorchTestCase
,
skipIfNoModule
,
skipIfNoRIR
if
_mod_utils
.
is_module_available
(
"pyroomacoustics"
):
import
pyroomacoustics
as
pra
@
skipIfNoModule
(
"pyroomacoustics"
)
@
skipIfNoRIR
class
CompatibilityTest
(
PytorchTestCase
):
dtype
=
torch
.
float64
device
=
torch
.
device
(
"cpu"
)
@
parameterized
.
expand
([(
1
,),
(
4
,)])
def
test_simulate_rir_ism_single_band
(
self
,
channel
):
"""Test simulate_rir_ism function in the case where absorption coefficients are identical for all walls."""
room_dim
=
torch
.
rand
(
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
5
mic_array
=
torch
.
rand
(
channel
,
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
1
source
=
torch
.
rand
(
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
4
max_order
=
3
# absorption is set as a float value indicating absorption coefficients are the same for every wall.
absorption
=
0.5
# compute rir signal by torchaudio implementation
actual
=
F
.
simulate_rir_ism
(
room_dim
,
source
,
mic_array
,
max_order
,
absorption
)
# compute rir signal by pyroomacoustics
room
=
pra
.
ShoeBox
(
room_dim
.
detach
().
numpy
(),
fs
=
16000
,
materials
=
pra
.
Material
(
absorption
),
max_order
=
max_order
,
ray_tracing
=
False
,
air_absorption
=
False
,
)
# mic_locs is a numpy array of dimension `(3, channel)`.
mic_locs
=
mic_array
.
transpose
(
0
,
1
).
double
().
detach
().
numpy
()
room
.
add_microphone_array
(
mic_locs
)
room
.
add_source
(
source
.
tolist
())
room
.
compute_rir
()
max_len
=
max
(
room
.
rir
[
i
][
0
].
shape
[
0
]
for
i
in
range
(
channel
))
expected
=
torch
.
zeros
(
channel
,
max_len
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
for
i
in
range
(
channel
):
expected
[
i
,
0
:
room
.
rir
[
i
][
0
].
shape
[
0
]]
=
torch
.
from_numpy
(
room
.
rir
[
i
][
0
])
self
.
assertEqual
(
expected
,
actual
,
atol
=
1e-3
,
rtol
=
1e-3
)
@
parameterized
.
expand
([(
1
,),
(
4
,)])
def
test_simulate_rir_ism_multi_band
(
self
,
channel
):
"""Test simulate_rir_ism in the case where absorption coefficients are different for all walls."""
room_dim
=
torch
.
rand
(
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
5
mic_array
=
torch
.
rand
(
channel
,
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
1
source
=
torch
.
rand
(
3
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
+
4
max_order
=
3
# absorption is set as a Tensor with dimensions `(7, 6)` indicating there are
# 6 walls and each wall has 7 absorption coefficients corresponds to 7 octave bands, respectively.
absorption
=
torch
.
rand
(
7
,
6
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
walls
=
[
"west"
,
"east"
,
"south"
,
"north"
,
"floor"
,
"ceiling"
]
room
=
pra
.
ShoeBox
(
room_dim
.
detach
().
numpy
(),
fs
=
16000
,
materials
=
{
walls
[
i
]:
pra
.
Material
(
{
"coeffs"
:
absorption
[:,
i
]
.
reshape
(
-
1
,
)
.
detach
()
.
numpy
(),
"center_freqs"
:
[
125.0
,
250.0
,
500.0
,
1000.0
,
2000.0
,
4000.0
,
8000.0
],
}
)
for
i
in
range
(
len
(
walls
))
},
max_order
=
max_order
,
ray_tracing
=
False
,
air_absorption
=
False
,
)
# mic_locs is a numpy array of dimension `(D, channel)`.
mic_locs
=
mic_array
.
transpose
(
0
,
1
).
double
().
detach
().
numpy
()
room
.
add_microphone_array
(
mic_locs
)
room
.
add_source
(
source
.
tolist
())
room
.
compute_rir
()
max_len
=
max
(
room
.
rir
[
i
][
0
].
shape
[
0
]
for
i
in
range
(
channel
))
expected
=
torch
.
zeros
(
channel
,
max_len
,
dtype
=
self
.
dtype
,
device
=
self
.
device
)
for
i
in
range
(
channel
):
expected
[
i
,
0
:
room
.
rir
[
i
][
0
].
shape
[
0
]]
=
torch
.
from_numpy
(
room
.
rir
[
i
][
0
])
actual
=
F
.
simulate_rir_ism
(
room_dim
,
source
,
mic_array
,
max_order
,
absorption
)
self
.
assertEqual
(
expected
,
actual
,
atol
=
1e-3
,
rtol
=
1e-3
)
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