-
Notifications
You must be signed in to change notification settings - Fork 6
/
audio_process.py
61 lines (57 loc) · 1.83 KB
/
audio_process.py
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
59
60
61
import torch
import torch.nn as nn
class AudioEncoder(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(1, 64, (3,3), (2,1), (1,1))
self.bn1 = nn.BatchNorm2d(64)
self.relu1 = nn.ReLU()
self.maxpool1 = nn.MaxPool2d((3,1),(2,1))
self.conv2 = nn.Conv2d(64, 192, (3,3), (1,1), (1,1))
self.bn2 = nn.BatchNorm2d(192)
self.relu2 = nn.ReLU()
self.maxpool2 = nn.MaxPool2d((3,3),(2,2))
self.conv3 = nn.Conv2d(192, 384, (3,3), (1,1), (1,1))
self.bn3 = nn.BatchNorm2d(384)
self.relu3 = nn.ReLU()
self.conv4 = nn.Conv2d(384, 256, (3,3), (1,1), (1,1))
self.bn4 = nn.BatchNorm2d(256)
self.relu4 = nn.ReLU()
self.conv5 = nn.Conv2d(256, 256, (3,3), (1,1), (1,1))
self.bn5 = nn.BatchNorm2d(256)
self.relu5 = nn.ReLU()
self.maxpool5 = nn.MaxPool2d((2,3),(2,2))
self.conv6 = nn.Conv2d(256, 512, (4,3), (1,1), (0,1))
self.bn6 = nn.BatchNorm2d(512)
self.relu6 = nn.ReLU()
self.conv7 = nn.Conv2d(512, 512, kernel_size=(1,1))
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = self.relu1(x)
x = self.maxpool1(x)
x = self.conv2(x)
x = self.bn2(x)
x = self.relu2(x)
x = self.maxpool2(x)
x = self.conv3(x)
x = self.bn3(x)
x = self.relu3(x)
x = self.conv4(x)
x = self.bn4(x)
x = self.relu4(x)
x = self.conv5(x)
x = self.bn5(x)
x = self.relu5(x)
x = self.maxpool5(x)
x = self.conv6(x)
x = self.bn6(x)
x = self.relu6(x)
x = self.conv7(x)
x = x.squeeze(-2)
return x
if __name__ == "__main__":
net = AudioEncoder()
x = torch.randn(1, 1, 80, 20)
y = net(x)
print(y.shape)