Skip to content

Commit

Permalink
Simplenet: Replace all functional operator calls with explicit layers
Browse files Browse the repository at this point in the history
  • Loading branch information
guyjacob committed Jan 21, 2019
1 parent 10ce938 commit 2438116
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions models/cifar10/simplenet_cifar.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,32 @@

__all__ = ['simplenet_cifar']


class Simplenet(nn.Module):
def __init__(self):
super(Simplenet, self).__init__()
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.relu_conv2 = nn.ReLU()
self.pool2 = nn.MaxPool2d(2, 2)
self.fc1 = nn.Linear(16 * 5 * 5, 120)
self.relu_fc1 = nn.ReLU()
self.fc2 = nn.Linear(120, 84)
self.relu_fc2 = nn.ReLU()
self.fc3 = nn.Linear(84, 10)

def forward(self, x):
x = self.pool(F.relu(self.conv1(x)))
x = self.pool(F.relu(self.conv2(x)))
x = self.pool1(self.relu_conv1(self.conv1(x)))
x = self.pool2(self.relu_conv2(self.conv2(x)))
x = x.view(-1, 16 * 5 * 5)
x = F.relu(self.fc1(x))
x = F.relu(self.fc2(x))
#x = nn.Threshold(0.2, 0.0)#ActivationZeroThreshold(x)
x = self.relu_fc1(self.fc1(x))
x = self.relu_fc2(self.fc2(x))
x = self.fc3(x)
return x


def simplenet_cifar():
model = Simplenet()
return model

0 comments on commit 2438116

Please sign in to comment.