Last active
November 21, 2018 19:46
-
-
Save pedrohbtp/308be5b9f0798a85800e99e35553975c to your computer and use it in GitHub Desktop.
This file contains 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
import torch | |
import torch.nn as nn | |
import torch.nn.functional as F | |
class Net(nn.Module): | |
def __init__(self): | |
super(Net, self).__init__() | |
# Defining 3 linear layers but NOT the way they should be connected | |
# Receives an array of length 240 and outputs one with length 120 | |
self.fc1 = nn.Linear(240, 120) | |
# Receives an array of length 120 and outputs one with length 60 | |
self.fc2 = nn.Linear(120, 60) | |
# Receives an array of length 60 and outputs one with length 10 | |
self.fc3 = nn.Linear(60, 10) | |
def forward(self, x): | |
# Defining the way that the layers of the model should be connected | |
# Performs RELU on the output of layer 'self.fc1 = nn.Linear(240, 120)' | |
x = F.relu(self.fc1(x)) | |
# Performs RELU on the output of layer 'self.fc2 = nn.Linear(120, 60)' | |
x = F.relu(self.fc2(x)) | |
# Passes the array through the last linear layer 'self.fc3 = nn.Linear(60, 10)' | |
x = self.fc3(x) | |
return x | |
net = Net() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment