forked from udacity/CVND---Gesture-Recognition
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
model.py
49 lines (39 loc) · 1.48 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import torch
import torch.nn as nn
class ConvColumn(nn.Module):
def __init__(self, num_classes):
super(ConvColumn, self).__init__()
#print("in init")
self.conv_layer1 = self._make_conv_layer(3, 64, (1, 2, 2), (1, 2, 2))
self.conv_layer2 = self._make_conv_layer(64, 128, (2, 2, 2), (2, 2, 2))
self.conv_layer3 = self._make_conv_layer(
128, 256, (2, 2, 2), (2, 2, 2))
self.conv_layer4 = self._make_conv_layer(
256, 256, (2, 2, 2), (2, 2, 2))
self.fc5 = nn.Linear(12800, 512)
self.fc5_act = nn.ELU()
self.fc6 = nn.Linear(512, num_classes)
def _make_conv_layer(self, in_c, out_c, pool_size, stride):
conv_layer = nn.Sequential(
nn.Conv3d(in_c, out_c, kernel_size=3, stride=1, padding=1),
nn.BatchNorm3d(out_c),
nn.ELU(),
nn.MaxPool3d(pool_size, stride=stride, padding=0)
)
return conv_layer
def forward(self, x):
x = self.conv_layer1(x)
x = self.conv_layer2(x)
x = self.conv_layer3(x)
x = self.conv_layer4(x)
x = x.view(x.size(0), -1)
x = self.fc5(x)
x = self.fc5_act(x)
x = self.fc6(x)
return x
if __name__ == "__main__":
print("in main")
input_tensor = torch.autograd.Variable(torch.rand(5, 3, 18, 84, 84))
model = ConvColumn(27) #ConvColumn(27).cuda()
output = model(input_tensor) #model(input_tensor.cuda())
print(output.size())