-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathtest_pooling.py
More file actions
58 lines (46 loc) · 1.41 KB
/
Copy pathtest_pooling.py
File metadata and controls
58 lines (46 loc) · 1.41 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import torch
import torch.nn
def test_pooling1d(device):
from speechbrain.nnet.pooling import Pooling1d
input = (
torch.tensor([1, 3, 2], device=device)
.unsqueeze(0)
.unsqueeze(-1)
.float()
)
pool = Pooling1d("max", 3).to(device)
output = pool(input)
assert output == 3
pool = Pooling1d("avg", 3).to(device)
output = pool(input)
assert output == 2
assert torch.jit.trace(pool, input)
def test_pooling2d(device):
from speechbrain.nnet.pooling import Pooling2d
input = (
torch.tensor([[1, 3, 2], [4, 6, 5]], device=device).float().unsqueeze(0)
)
pool = Pooling2d("max", (2, 3)).to(device)
output = pool(input)
assert output == 6
input = (
torch.tensor([[1, 3, 2], [4, 6, 5]], device=device).float().unsqueeze(0)
)
pool = Pooling2d("max", (1, 3)).to(device)
output = pool(input)
assert output[0][0] == 3
assert output[0][1] == 6
input = (
torch.tensor([[1, 3, 2], [4, 6, 5]], device=device).float().unsqueeze(0)
)
pool = Pooling2d("avg", (2, 3)).to(device)
output = pool(input)
assert output == 3.5
input = (
torch.tensor([[1, 3, 2], [4, 6, 5]], device=device).float().unsqueeze(0)
)
pool = Pooling2d("avg", (1, 3)).to(device)
output = pool(input)
assert output[0][0] == 2
assert output[0][1] == 5
assert torch.jit.trace(pool, input)