forked from M-Nauta/TCDF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
33 lines (26 loc) · 1.18 KB
/
model.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
import torch as th
from torch import nn
import torch.nn.functional as F
from torch.autograd import Variable
from depthwise import DepthwiseNet
from torch.nn.utils import weight_norm
import numpy as np
class ADDSTCN(nn.Module):
def __init__(self, target, input_size, num_levels, kernel_size, cuda, dilation_c):
super(ADDSTCN, self).__init__()
self.target=target
self.dwn = DepthwiseNet(self.target, input_size, num_levels, kernel_size=kernel_size, dilation_c=dilation_c)
self.pointwise = nn.Conv1d(input_size, 1, 1)
self._attention = th.ones(input_size,1)
self._attention = Variable(self._attention, requires_grad=False)
self.fs_attention = th.nn.Parameter(self._attention.data)
if cuda:
self.dwn = self.dwn.cuda()
self.pointwise = self.pointwise.cuda()
self._attention = self._attention.cuda()
def init_weights(self):
self.pointwise.weight.data.normal_(0, 0.1)
def forward(self, x):
y1=self.dwn(x*F.softmax(self.fs_attention, dim=0))
y1 = self.pointwise(y1)
return y1.transpose(1,2)