-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
46 lines (30 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
import torch.nn as nn
import torch.nn.functional as F
class BotDemineur(nn.Module):
def __init__(self, rows = 16, cols = 30, outputs = 480):
super(BotDemineur, self).__init__()
self.conv1 = nn.Conv2d(1, 3, kernel_size=3, padding=1)
self.bn1 = nn.BatchNorm2d(3)
self.conv2 = nn.Conv2d(3, 3, kernel_size=3)
self.bn2 = nn.BatchNorm2d(3)
# Due to no padding, the size of the output of conv2 is w-2 x h-2
linear_output_size = (rows - 2) * (cols - 2) * 3
self.head = nn.Linear(linear_output_size, outputs)
def forward(self, x):
x = F.relu(self.bn1(self.conv1(x)))
x = F.relu(self.bn2(self.conv2(x)))
return self.head(x.view(x.size(0), -1))
class BotDemineurV2(nn.Module):
def __init__(self, rows = 16, cols = 30, outputs = 480):
super(BotDemineur, self).__init__()
self.conv1 = nn.Conv2d(1, 3, kernel_size=3, padding=1)
self.bn1 = nn.BatchNorm2d(3)
self.conv2 = nn.Conv2d(3, 3, kernel_size=3)
self.bn2 = nn.BatchNorm2d(3)
# Due to no padding, the size of the output of conv2 is w-2 x h-2
linear_output_size = (rows - 2) * (cols - 2) * 3
self.head = nn.Linear(linear_output_size, outputs)
def forward(self, x):
x = F.relu(self.bn1(self.conv1(x)))
x = F.relu(self.bn2(self.conv2(x)))
return self.head(x.view(x.size(0), -1))