Created
January 7, 2020 21:58
-
-
Save johnolafenwa/c4ad843e85b2ee032f58de75dd74bc4a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Unit(nn.Module): | |
def __init__(self,in_channels,out_channels): | |
super(Unit,self).__init__() | |
self.conv = nn.Conv2d(in_channels=in_channels,kernel_size=3,out_channels=out_channels,stride=1,padding=1) | |
self.bn = nn.BatchNorm2d(num_features=out_channels) | |
self.relu = nn.ReLU() | |
def forward(self,input): | |
output = self.conv(input) | |
output = self.bn(output) | |
output = self.relu(output) | |
return output | |
class SimpleNet(nn.Module): | |
def __init__(self,num_classes=10): | |
super(SimpleNet,self).__init__() | |
#Create 14 layers of the unit with max pooling in between | |
self.net = nn.Sequential( | |
Unit(in_channels=3,out_channels=32), | |
Unit(in_channels=32, out_channels=32), | |
Unit(in_channels=32, out_channels=32), | |
nn.MaxPool2d(kernel_size=2), | |
Unit(in_channels=32, out_channels=64), | |
Unit(in_channels=64, out_channels=64), | |
Unit(in_channels=64, out_channels=64), | |
Unit(in_channels=64, out_channels=64), | |
nn.MaxPool2d(kernel_size=2), | |
Unit(in_channels=64, out_channels=128), | |
Unit(in_channels=128, out_channels=128), | |
Unit(in_channels=128, out_channels=128), | |
Unit(in_channels=128, out_channels=128), | |
nn.MaxPool2d(kernel_size=2), | |
Unit(in_channels=128, out_channels=128), | |
Unit(in_channels=128, out_channels=128), | |
Unit(in_channels=128, out_channels=128), | |
nn.AdaptiveAvgPool2d(1) | |
) | |
self.fc = nn.Linear(in_features=128,out_features=num_classes) | |
def forward(self, input): | |
output = self.net(input) | |
output = output.view(-1,128) | |
output = self.fc(output) | |
return output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment