Skip to content
Snippets Groups Projects
Commit 24381169 authored by Guy Jacob's avatar Guy Jacob
Browse files

Simplenet: Replace all functional operator calls with explicit layers

parent 10ce938c
No related branches found
No related tags found
No related merge requests found
...@@ -19,26 +19,32 @@ import torch.nn.functional as F ...@@ -19,26 +19,32 @@ import torch.nn.functional as F
__all__ = ['simplenet_cifar'] __all__ = ['simplenet_cifar']
class Simplenet(nn.Module): class Simplenet(nn.Module):
def __init__(self): def __init__(self):
super(Simplenet, self).__init__() super(Simplenet, self).__init__()
self.conv1 = nn.Conv2d(3, 6, 5) self.conv1 = nn.Conv2d(3, 6, 5)
self.pool = nn.MaxPool2d(2, 2) self.relu_conv1 = nn.ReLU()
self.pool1 = nn.MaxPool2d(2, 2)
self.conv2 = nn.Conv2d(6, 16, 5) self.conv2 = nn.Conv2d(6, 16, 5)
self.relu_conv2 = nn.ReLU()
self.pool2 = nn.MaxPool2d(2, 2)
self.fc1 = nn.Linear(16 * 5 * 5, 120) self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.relu_fc1 = nn.ReLU()
self.fc2 = nn.Linear(120, 84) self.fc2 = nn.Linear(120, 84)
self.relu_fc2 = nn.ReLU()
self.fc3 = nn.Linear(84, 10) self.fc3 = nn.Linear(84, 10)
def forward(self, x): def forward(self, x):
x = self.pool(F.relu(self.conv1(x))) x = self.pool1(self.relu_conv1(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x))) x = self.pool2(self.relu_conv2(self.conv2(x)))
x = x.view(-1, 16 * 5 * 5) x = x.view(-1, 16 * 5 * 5)
x = F.relu(self.fc1(x)) x = self.relu_fc1(self.fc1(x))
x = F.relu(self.fc2(x)) x = self.relu_fc2(self.fc2(x))
#x = nn.Threshold(0.2, 0.0)#ActivationZeroThreshold(x)
x = self.fc3(x) x = self.fc3(x)
return x return x
def simplenet_cifar(): def simplenet_cifar():
model = Simplenet() model = Simplenet()
return model return model
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment