-
Notifications
You must be signed in to change notification settings - Fork 2
/
cnnModel.py
45 lines (40 loc) · 1.32 KB
/
cnnModel.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
import torch.nn as nn
import torch.nn.functional as F
class CNN(nn.Module):
def __init__(self):
super(CNN,self).__init__()
self.conv1=nn.Sequential(
nn.Conv2d(in_channels=1,out_channels=32,kernel_size=5,padding=2),
nn.BatchNorm2d(32),
nn.ReLU(),
)
self.conv2=nn.Sequential(
nn.Conv2d(in_channels=32,out_channels=32,kernel_size=5,padding=2),
nn.BatchNorm2d(32),
nn.Dropout(0.25),
nn.ReLU(),
nn.MaxPool2d(2)
)
self.conv3=nn.Sequential(
nn.Conv2d(in_channels=32,out_channels=64,kernel_size=5,padding=2),
nn.BatchNorm2d(64),
nn.ReLU(),
)
self.conv4=nn.Sequential(
nn.Conv2d(in_channels=64,out_channels=64,kernel_size=5,padding=2),
nn.BatchNorm2d(64),
nn.Dropout(0.25),
nn.ReLU(),
nn.MaxPool2d(2)
)
self.fc1=nn.Sequential(
nn.Linear(in_features=64*7*7,out_features=10)
)
def forward(self,t):
out=self.conv1(t)
out=self.conv2(out)
out=self.conv3(out)
out=self.conv4(out)
out=out.reshape(-1,64*7*7)
out=self.fc1(out)
return out