-
Notifications
You must be signed in to change notification settings - Fork 59
/
models.py
executable file
·74 lines (59 loc) · 2.43 KB
/
models.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
62
63
64
65
66
67
68
69
70
71
72
73
74
# -*- coding: utf-8 -*-
import numpy as np
import torch
from torch.autograd import Variable
import torch.nn.functional as F
import torch.nn as nn
from torch.nn import init
class TEM(torch.nn.Module):
def __init__(self, opt):
super(TEM, self).__init__()
self.feat_dim = opt["tem_feat_dim"]
self.temporal_dim = opt["temporal_scale"]
self.batch_size= opt["tem_batch_size"]
self.c_hidden = opt["tem_hidden_dim"]
self.tem_best_loss = 10000000
self.output_dim = 3
self.conv1 = torch.nn.Conv1d(in_channels=self.feat_dim, out_channels=self.c_hidden,kernel_size=3,stride=1,padding=1,groups=1)
self.conv2 = torch.nn.Conv1d(in_channels=self.c_hidden,out_channels=self.c_hidden,kernel_size=3,stride=1,padding=1,groups=1)
self.conv3 = torch.nn.Conv1d(in_channels=self.c_hidden,out_channels=self.output_dim, kernel_size=1,stride=1,padding=0)
self.reset_params()
@staticmethod
def weight_init(m):
if isinstance(m, nn.Conv2d):
init.xavier_normal(m.weight)
init.constant(m.bias, 0)
def reset_params(self):
for i, m in enumerate(self.modules()):
self.weight_init(m)
def forward(self, x):
x = F.relu(self.conv1(x))
x = F.relu(self.conv2(x))
x = torch.sigmoid(0.01*self.conv3(x))
return x
class PEM(torch.nn.Module):
def __init__(self,opt):
super(PEM, self).__init__()
self.feat_dim = opt["pem_feat_dim"]
self.batch_size = opt["pem_batch_size"]
self.hidden_dim = opt["pem_hidden_dim"]
self.u_ratio_m = opt["pem_u_ratio_m"]
self.u_ratio_l = opt["pem_u_ratio_l"]
self.output_dim = 1
self.pem_best_loss = 1000000
self.fc1 = torch.nn.Linear(in_features=self.feat_dim,out_features=self.hidden_dim,bias =True)
self.fc2 = torch.nn.Linear(in_features=self.hidden_dim,out_features=self.output_dim,bias =True)
self.reset_params()
@staticmethod
def weight_init(m):
if isinstance(m, nn.Conv2d):
init.xavier_uniform_(m.weight)
#init.xavier_normal(m.weight)
init.constant(m.bias, 0)
def reset_params(self):
for i, m in enumerate(self.modules()):
self.weight_init(m)
def forward(self, x):
x = F.relu(0.1*self.fc1(x))
x = torch.sigmoid(0.1*self.fc2(x))
return x