-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.py
More file actions
117 lines (108 loc) · 3.44 KB
/
model.py
File metadata and controls
117 lines (108 loc) · 3.44 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import torch
from torch import nn
import torch.nn.functional as F
# Model based on NVidia paper: https://arxiv.org/pdf/1604.07316.pdf
class TrackmaniaNet(nn.Module):
def __init__(self, drop_out=0.2):
super(TrackmaniaNet, self).__init__()
self.drop_out = drop_out
self.conv1 = nn.Conv2d(1, 24, 5, stride=2, padding=1)
self.bn1 = nn.BatchNorm2d(24)
self.conv2 = nn.Conv2d(24, 36, 5, stride=2, padding=1)
self.bn2 = nn.BatchNorm2d(36)
self.conv3 = nn.Conv2d(36, 48, 5, stride=2, padding=1)
self.bn3 = nn.BatchNorm2d(48)
self.conv4 = nn.Conv2d(48, 64, 3, padding=1)
self.bn4 = nn.BatchNorm2d(64)
self.conv5 = nn.Conv2d(64, 64, 3, padding=1)
self.bn5 = nn.BatchNorm2d(64)
self.flat = nn.Flatten(1)
self.fc1 = nn.Linear(3136, 1164)
self.fc2 = nn.Linear(1164, 100)
self.fc3 = nn.Linear(100, 50)
self.fc4 = nn.Linear(50, 10)
self.fc5 = nn.Linear(10, 2)
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = F.relu(x)
x = self.conv2(x)
x = self.bn2(x)
x = F.relu(x)
x = self.conv3(x)
x = self.bn3(x)
x = F.relu(x)
x = self.conv4(x)
x = self.bn4(x)
x = F.relu(x)
x = self.conv5(x)
x = self.bn5(x)
x = F.relu(x)
x = self.flat(x)
x = self.fc1(x)
x = F.relu(x)
x = F.dropout(x, self.drop_out)
x = self.fc2(x)
x = F.relu(x)
x = F.dropout(x, self.drop_out)
x = self.fc3(x)
x = F.relu(x)
x = F.dropout(x, self.drop_out)
x = self.fc4(x)
x = F.relu(x)
x = F.dropout(x, self.drop_out)
x = self.fc5(x)
x = torch.atan(x)
return x
class TrackmaniaNetOnlySteer(nn.Module):
def __init__(self, drop_out=0.2):
super(TrackmaniaNetOnlySteer, self).__init__()
self.drop_out = drop_out
self.conv1 = nn.Conv2d(1, 24, 5, stride=2, padding=1)
self.bn1 = nn.BatchNorm2d(24)
self.conv2 = nn.Conv2d(24, 36, 5, stride=2, padding=1)
self.bn2 = nn.BatchNorm2d(36)
self.conv3 = nn.Conv2d(36, 48, 5, stride=2, padding=1)
self.bn3 = nn.BatchNorm2d(48)
self.conv4 = nn.Conv2d(48, 64, 3, padding=1)
self.bn4 = nn.BatchNorm2d(64)
self.conv5 = nn.Conv2d(64, 64, 3, padding=1)
self.bn5 = nn.BatchNorm2d(64)
self.flat = nn.Flatten(1)
self.fc1 = nn.Linear(576, 1164)
self.fc2 = nn.Linear(1164, 100)
self.fc3 = nn.Linear(100, 50)
self.fc4 = nn.Linear(50, 10)
self.fc5 = nn.Linear(10, 1)
def forward(self, x):
x = self.conv1(x)
x = self.bn1(x)
x = F.relu(x)
x = self.conv2(x)
x = self.bn2(x)
x = F.relu(x)
x = self.conv3(x)
x = self.bn3(x)
x = F.relu(x)
x = self.conv4(x)
x = self.bn4(x)
x = F.relu(x)
x = self.conv5(x)
x = self.bn5(x)
x = F.relu(x)
x = self.flat(x)
x = self.fc1(x)
x = F.relu(x)
x = F.dropout(x, self.drop_out)
x = self.fc2(x)
x = F.relu(x)
x = F.dropout(x, self.drop_out)
x = self.fc3(x)
x = F.relu(x)
x = F.dropout(x, self.drop_out)
x = self.fc4(x)
x = F.relu(x)
x = F.dropout(x, self.drop_out)
x = self.fc5(x)
x = torch.atan(x)
return x