forked from speechbrain/speechbrain
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pooling.py
More file actions
43 lines (31 loc) · 1.08 KB
/
Copy pathtest_pooling.py
File metadata and controls
43 lines (31 loc) · 1.08 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
import torch
import torch.nn
def test_pooling1d():
from speechbrain.nnet.pooling import Pooling1d
input = torch.tensor([1, 3, 2]).unsqueeze(0).unsqueeze(-1).float()
pool = Pooling1d("max", 3)
output = pool(input)
assert output == 3
pool = Pooling1d("avg", 3)
output = pool(input)
assert output == 2
def test_pooling2d():
from speechbrain.nnet.pooling import Pooling2d
input = torch.tensor([[1, 3, 2], [4, 6, 5]]).float().unsqueeze(0)
pool = Pooling2d("max", (2, 3))
output = pool(input)
assert output == 6
input = torch.tensor([[1, 3, 2], [4, 6, 5]]).float().unsqueeze(0)
pool = Pooling2d("max", (1, 3))
output = pool(input)
assert output[0][0] == 3
assert output[0][1] == 6
input = torch.tensor([[1, 3, 2], [4, 6, 5]]).float().unsqueeze(0)
pool = Pooling2d("avg", (2, 3))
output = pool(input)
assert output == 3.5
input = torch.tensor([[1, 3, 2], [4, 6, 5]]).float().unsqueeze(0)
pool = Pooling2d("avg", (1, 3))
output = pool(input)
assert output[0][0] == 2
assert output[0][1] == 5