Skip to content

Instantly share code, notes, and snippets.

@demacdolincoln
Created January 11, 2019 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demacdolincoln/f550a5da1cdd6547ffaa19a9f1849519 to your computer and use it in GitHub Desktop.
Save demacdolincoln/f550a5da1cdd6547ffaa19a9f1849519 to your computer and use it in GitHub Desktop.
simple pytorch cnn
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