Created
January 11, 2019 16:33
-
-
Save demacdolincoln/f550a5da1cdd6547ffaa19a9f1849519 to your computer and use it in GitHub Desktop.
simple pytorch cnn
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CNN(nn.Module): | |
def __init__(self): | |
super(CNN, self).__init__() | |
self.conv1 = nn.Sequential( | |
nn.Conv2d(1, 16, 5, stride=2), | |
nn.ReLU(), | |
nn.MaxPool2d(kernel_size=2) | |
) | |
self.conv2 = nn.Sequential( | |
nn.Conv2d(16, 32, 5, stride=2), | |
nn.ReLU(), | |
nn.MaxPool2d(kernel_size=2) | |
) | |
self.fc1 = nn.Linear(32, 50) | |
self.fc2 = nn.Linear(50, 10) | |
def forward(self, x): | |
x = self.conv1(x) | |
x = self.conv2(x) | |
# print(x.shape) | |
x = x.view(x.shape[0], -1) | |
x = F.relu(self.fc1(x)) | |
x = self.fc2(x) | |
return x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment