-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
30 lines (24 loc) · 884 Bytes
/
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
import torch
import torch.nn as nn
import torch.nn.functional as F
class LeNet(nn.Module):
def __init__(self):
super(LeNet,self).__init__()
self.conv1 = nn.Conv2d(in_channels=1,out_channels=6,kernel_size=5,stride=1)
self.conv2 = nn.Conv2d(in_channels=6,out_channels=16,kernel_size=5,stride=1)
self.conv3 = nn.Conv2d(in_channels=16,out_channels=120,kernel_size=4,stride=1)
self.fc1 = nn.Linear(in_features=120,out_features=84,bias=True)
self.fc2 = nn.Linear(in_features=84,out_features=10,bias=True)
def forward(self,x):
x = self.conv1(x)
x = F.max_pool2d(x,2)
x = F.relu(x)
x = self.conv2(x)
x = F.max_pool2d(x,2)
x = F.relu(x)
x = self.conv3(x)
x = F.relu(x)
x = x.view(x.shape[0],-1)
x = self.fc1(x)
x = self.fc2(x)
return x