-
Notifications
You must be signed in to change notification settings - Fork 1
/
NN_networks.py
80 lines (69 loc) · 3.29 KB
/
NN_networks.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
75
76
77
78
79
80
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Nov 10 13:58:49 2022
@author: qiang
"""
import torch.nn as nn
import torch
class SlipDetectGlobalGru(nn.Module):
def __init__(self,
args,
bias=True):
super(SlipDetectGlobalGru, self).__init__()
self.projector = nn.Sequential(nn.Linear(args.input_dim, 1024, bias=bias),
nn.BatchNorm1d(1024),
nn.ReLU(),
nn.Linear(1024, args.hidden_dim, bias=bias),
nn.BatchNorm1d(args.hidden_dim),
nn.ReLU(),
)
self.rnn = nn.GRUCell(input_size = args.hidden_dim,
hidden_size = args.hidden_dim,
bias = bias)
self.predictor = nn.Sequential(nn.Linear(args.hidden_dim, 256, bias=bias),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.Linear(256, 128, bias=bias),
nn.BatchNorm1d(128),
nn.ReLU(),
nn.Linear(128, args.categories, bias=bias),
nn.BatchNorm1d(args.categories),
nn.Softmax(dim=1),
)
def forward(self,inp, h):
x = self.projector(inp)
h = self.rnn(x, h)
x = self.predictor(h)
return x,h
class SlipDetectGlobalLstm(nn.Module):
def __init__(self,
args,
bias=True):
super(SlipDetectGlobalLstm, self).__init__()
self.projector = nn.Sequential(nn.Linear(args.input_dim, 1024, bias=bias),
nn.BatchNorm1d(1024),
nn.ReLU(),
nn.Linear(1024, args.hidden_dim, bias=bias),
nn.BatchNorm1d(args.hidden_dim),
nn.ReLU(),
)
self.rnn = nn.LSTMCell(input_size = args.hidden_dim,
hidden_size = args.hidden_dim,
bias = bias)
self.predictor = nn.Sequential(nn.Linear(args.hidden_dim*2, 256, bias=bias),
nn.BatchNorm1d(256),
nn.ReLU(),
nn.Linear(256, 128, bias=bias),
nn.BatchNorm1d(128),
nn.ReLU(),
nn.Linear(128, args.categories, bias=bias),
nn.BatchNorm1d(args.categories),
nn.Softmax(dim=1),
)
def forward(self,inp, h,c):
x = self.projector(inp)
h, c = self.rnn(x, (h,c))
x = torch.cat((h,c),dim=1)
x = self.predictor(x)
return x,h,c