forked from asteroid-team/asteroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbinarize_test.py
More file actions
25 lines (22 loc) · 870 Bytes
/
Copy pathbinarize_test.py
File metadata and controls
25 lines (22 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import torch
from asteroid.binarize import Binarize
def test_Binarize():
# fmt: off
inputs_list = [
torch.Tensor([0.1, 0.6, 0.2, 0.6, 0.1, 0.1, 0.1, 0.7, 0.7, 0.7, 0.1, 0.7, 0.7, 0.7, 0.1,
0.8, 0.9, 0.2, 0.7, 0.1, 0.1, 0.1, 0.8, 0.1]),
torch.Tensor([0.1, 0.1, 0.2, 0.1]),
torch.Tensor([0.7, 0.7, 0.7, 0.7]),
torch.Tensor([0.1, 0.7]),
]
# fmt: on
expected_result_list = [
torch.Tensor([0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]),
torch.Tensor([0.0, 0.0, 0.0, 0.0]),
torch.Tensor([1, 1, 1, 1]),
torch.Tensor([0.0, 0.0]),
]
binarizer = Binarize(0.5, 3, 1)
for i in range(len(inputs_list)):
result = binarizer(inputs_list[i].unsqueeze(0).unsqueeze(0))
assert torch.allclose(result, expected_result_list[i])