Repository: pytorch/vision

Issue:
VGG classifier setting different from Original paper
One of the dropout layer was "wrongly" inserted.
The original final layers of Caffe Version (https://gist.github.com/ksimonyan/211839e770f7b538e2d8) is:
self.classifier = nn.Sequential(
            nn.Linear(512 * 7 * 7, 4096),
            nn.ReLU(True),
            nn.Dropout(),
            nn.Linear(4096, 4096),
            nn.ReLU(True),
            nn.Dropout()
            nn.Linear(4096, 1000),
        )
This won't make difference when we use model.eval(), but will make discrepancy if we want to finetune VggNet by loading Caffe's parameters.


Discussion:
Thanks for catching this. I'll fix this and retrain the VGG models.

On Fri, Mar 10, 2017 at 1:44 AM Licheng Yu <notifications@github.com> wrote:

> One of the dropout layer was "wrongly" inserted.
> The original final layers of Caffe Version (
> https://gist.github.com/ksimonyan/211839e770f7b538e2d8) is:
> self.classifier = nn.Sequential(
> nn.Linear(512 * 7 * 7, 4096),
> nn.ReLU(True),
> nn.Dropout(),
> nn.Linear(4096, 4096),
> nn.ReLU(True),
> nn.Dropout()
> nn.Linear(4096, 1000),
> )
> This won't make difference when we use model.eval(), but will make
> discrepancy if we want to finetune VggNet by loading Caffe's parameters.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/pytorch/vision/issues/92>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AAoB-mQoAanKtu7ZOeBuY48ynFDezv_0ks5rkPFjgaJpZM4MZB_2>
> .
>


Resolving patch:
diff --git a/torchvision/models/__init__.py b/torchvision/models/__init__.py
--- a/torchvision/models/__init__.py
+++ b/torchvision/models/__init__.py
@@ -37,10 +37,10 @@
 ResNet-152               21.69           5.94
 Inception v3             22.55           6.44
 AlexNet                  43.45           20.91
-VGG-11                   32.14           12.12
-VGG-13                   31.04           11.40
-VGG-16                   29.11           10.17
-VGG-19                   28.42           9.69
+VGG-11                   30.98           11.37
+VGG-13                   30.07           10.75
+VGG-16                   28.41           9.62
+VGG-19                   27.62           9.12
 SqueezeNet 1.0           41.90           19.58
 SqueezeNet 1.1           41.81           19.38
 ======================== =============   =============
diff --git a/torchvision/models/vgg.py b/torchvision/models/vgg.py
--- a/torchvision/models/vgg.py
+++ b/torchvision/models/vgg.py
@@ -10,10 +10,10 @@
 
 
 model_urls = {
-    'vgg11': 'https://download.pytorch.org/models/vgg11-fb7e83b2.pth',
-    'vgg13': 'https://download.pytorch.org/models/vgg13-58758d87.pth',
-    'vgg16': 'https://download.pytorch.org/models/vgg16-82412952.pth',
-    'vgg19': 'https://download.pytorch.org/models/vgg19-341d7465.pth',
+    'vgg11': 'https://download.pytorch.org/models/vgg11-bbd30ac9.pth',
+    'vgg13': 'https://download.pytorch.org/models/vgg13-c768596a.pth',
+    'vgg16': 'https://download.pytorch.org/models/vgg16-397923af.pth',
+    'vgg19': 'https://download.pytorch.org/models/vgg19-dcbb9e9d.pth',
 }
 
 
@@ -23,12 +23,12 @@ def __init__(self, features):
         super(VGG, self).__init__()
         self.features = features
         self.classifier = nn.Sequential(
-            nn.Dropout(),
             nn.Linear(512 * 7 * 7, 4096),
             nn.ReLU(True),
             nn.Dropout(),
             nn.Linear(4096, 4096),
             nn.ReLU(True),
+            nn.Dropout(),
             nn.Linear(4096, 1000),
         )
         self._initialize_weights()


Test patch: