-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCNN.py
34 lines (31 loc) · 1.1 KB
/
CNN.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
"""
5.5
use 2x2 max_pool
conv layers just change channels of images
channels follow the order of [64, 128, 256, 512, 512, 512, 512]
"""
from torch import nn
import torch.nn.functional as f
class CNN(nn.Module):
def __init__(self):
super(CNN, self).__init__()
self.model = nn.Sequential(
nn.Conv2d(in_channels=3, out_channels=64, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(64),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(in_channels=64, out_channels=128, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(128),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.Conv2d(in_channels=128, out_channels=256, kernel_size=3, stride=1, padding=1),
nn.BatchNorm2d(256),
nn.ReLU(),
nn.MaxPool2d(kernel_size=2, stride=2),
nn.AvgPool2d(kernel_size=1, stride=1),
nn.Flatten(),
nn.Linear(in_features=262144, out_features=10)
)
def forward(self, x):
x = self.model(x)
return x