Skip to content

Instantly share code, notes, and snippets.

@erykml
Created January 25, 2019 21:52
Show Gist options
  • Select an option

  • Save erykml/f1049009a8ee780edb9a37d033b74c43 to your computer and use it in GitHub Desktop.

Select an option

Save erykml/f1049009a8ee780edb9a37d033b74c43 to your computer and use it in GitHub Desktop.
# create class Flatten to flatten the tensor
class Flatten(nn.Module):
def forward(self, x):
return x.view(x.size()[0], -1)
# use OrderedDict to give meaningful names for layers
model = nn.Sequential(OrderedDict([
('conv_1', nn.Conv2d(3, 16, 3, padding=1)),
('relu_1', nn.ReLU()),
('max_pool_1', nn.MaxPool2d(2, 2)),
('conv_2', nn.Conv2d(16, 32, 3, padding=1)),
('relu_2', nn.ReLU()),
('max_pool_2', nn.MaxPool2d(2, 2)),
('conv_3', nn.Conv2d(32, 64, 3, padding=1)),
('relu_3', nn.ReLU()),
('max_pool_3', nn.MaxPool2d(2, 2)),
('flatten', Flatten()),
('dropout_1', nn.Dropout(0.25)),
('fc_1', nn.Linear(64 * 16 * 16, 128)),
('relu_4', nn.ReLU()),
('dropout', nn.Dropout(0.25)),
('fc_2', nn.Linear(128, 1))
]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment