-
Notifications
You must be signed in to change notification settings - Fork 1
/
cnn_model.py
36 lines (29 loc) · 1.03 KB
/
cnn_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
import torch
import torch.nn as nn
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
self.convolutional_layer = nn.Sequential(
#First layer
nn.Conv2d(in_channels=3, out_channels=32, kernel_size=3, padding=1),
nn.LeakyReLU(inplace=True),
nn.MaxPool2d(kernel_size = 2, stride = 2),
#Second layer
nn.Conv2d(in_channels=32, out_channels=32, kernel_size=3, padding=1),
nn.LeakyReLU(inplace=True),
nn.MaxPool2d(kernel_size = 2, stride = 2),
)
self.fullyconnected_layer = nn.Sequential(
#Fully connected layer
nn.Dropout(p=0.1),
nn.Flatten(),
nn.Linear(32*64*64,64),
nn.ReLU(inplace=True),
nn.Dropout(p=0.1),
nn.Linear(64, 4)
)
def forward(self, x):
x = self.convolutional_layer(x)
x = x.view(x.size(0), -1)
x = self.fullyconnected_layer(x)
return x