Skip to content

Instantly share code, notes, and snippets.

@ashhadulislam
Last active January 27, 2022 16:25
Show Gist options
  • Save ashhadulislam/21d78a9b5a3cdb47aa704018828c06df to your computer and use it in GitHub Desktop.
Save ashhadulislam/21d78a9b5a3cdb47aa704018828c06df to your computer and use it in GitHub Desktop.
import torch
import torch.nn as nn
import torch.nn.functional as F
class MNISTNet(nn.Module):
"""Feedfoward neural network with 1 hidden layer"""
def __init__(self):
super(MNISTNet, self).__init__()
self.fc1 = nn.Linear(28*28, 256)
self.fc2 = nn.Linear(256, 128)
self.fc3 = nn.Linear(128, 64)
self.fc4 = nn.Linear(64, 10)
self.fc4.is_classifier = True
def forward(self, x):
x = x.view(x.shape[0], -1)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
x = F.relu(self.fc3(x))
x = self.fc4(x)
return F.log_softmax(x, dim=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment