-
Notifications
You must be signed in to change notification settings - Fork 0
/
tsai_models.py
50 lines (42 loc) · 1.78 KB
/
tsai_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
from torch import nn
import torch.nn.functional as F
from tsai.models.InceptionTime import InceptionTime
from tsai.models.ResNet import ResNet
class InceptionTimeClassifier(nn.Module):
def __init__(self, model_config, data_config):
super(InceptionTimeClassifier, self).__init__()
self.c_in = data_config['channels']
self.c_out = data_config['n_classes']
self.seq_len = data_config['timesteps']
self.depth = model_config['inception_depth']
self.inct = InceptionTime(self.c_in, c_out=self.c_out, seq_len=self.seq_len, depth=self.depth)
self.input_dropout = nn.Dropout(p=model_config['classifier_input_dropout_perc'])
layers = []
if model_config['classifier_use_input_dropout']:
layers.append(self.input_dropout)
layers.append(self.inct)
self.pipeline = nn.Sequential(*layers)
def forward(self, X):
x = self.pipeline(X)
return x
def computeLoss(self, logits, labels):
Lacc = F.cross_entropy(logits, labels)
return Lacc
class ResNetClassifier(nn.Module):
def __init__(self, model_config, data_config):
super(ResNetClassifier, self).__init__()
self.c_in = data_config['channels']
self.c_out = data_config['n_classes']
self.resnet = ResNet(self.c_in, self.c_out)
self.input_dropout = nn.Dropout(p=model_config['classifier_input_dropout_perc'])
layers = []
if model_config['classifier_use_input_dropout']:
layers.append(self.input_dropout)
layers.append(self.resnet)
self.pipeline = nn.Sequential(*layers)
def forward(self, X):
x = self.pipeline(X)
return x
def computeLoss(self, logits, labels):
Lacc = F.cross_entropy(logits, labels)
return Lacc