Commit 6434dead authored by ekka's avatar ekka Committed by Francisco Massa
Browse files

Changing to AdaptiveAvgPool2d on Alexnet (#746)

The update allows Alexnet to process images larger or smaller than prescribed imagenet size using adaptive average pooling. Will be useful while finetuning or testing on different resolution images. Similar to https://github.com/pytorch/vision/pull/643 and https://github.com/pytorch/vision/pull/672. I did not include adaptive avg pool in features or classifier block so that these predefined blocks can be used as it is.
parent 9e125514
...@@ -29,6 +29,7 @@ class AlexNet(nn.Module): ...@@ -29,6 +29,7 @@ class AlexNet(nn.Module):
nn.ReLU(inplace=True), nn.ReLU(inplace=True),
nn.MaxPool2d(kernel_size=3, stride=2), nn.MaxPool2d(kernel_size=3, stride=2),
) )
self.avgpool = nn.AdaptiveAvgPool2d((6, 6))
self.classifier = nn.Sequential( self.classifier = nn.Sequential(
nn.Dropout(), nn.Dropout(),
nn.Linear(256 * 6 * 6, 4096), nn.Linear(256 * 6 * 6, 4096),
...@@ -41,6 +42,7 @@ class AlexNet(nn.Module): ...@@ -41,6 +42,7 @@ class AlexNet(nn.Module):
def forward(self, x): def forward(self, x):
x = self.features(x) x = self.features(x)
x = self.avgpool(x)
x = x.view(x.size(0), 256 * 6 * 6) x = x.view(x.size(0), 256 * 6 * 6)
x = self.classifier(x) x = self.classifier(x)
return x return x
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment