Pretrained VGG-Face model

username: pvskand
cooked: <p>I have searched for vgg-face pretrained model in pytorch, but couldn’t find it. Is there a github repo for the pretrained model of vgg-face in pytorch?</p>

username: shashankvkt
cooked: <p>Hi! I hope it’s not too late.<br>
I had found this link pertaining to details regarding vgg-face model along with its weights in the link below. Scroll down to the vgg-face section and download your requirements.</p>
<p><a href="http://www.robots.ox.ac.uk/~albanie/pytorch-models.html" class="onebox" target="_blank" rel="nofollow noopener">http://www.robots.ox.ac.uk/~albanie/pytorch-models.html</a></p>
<p>Hope this helps.</p>

username: pvskand
cooked: <p>Thank you <a class="mention" href="/u/shashankvkt">@shashankvkt</a>.</p>

username: cydonia999
cooked: <p>I hope this also helps.<br>
<aside class="onebox whitelistedgeneric">
  <header class="source">
      <img src="https://assets-cdn.github.com/favicon.ico" class="site-icon" width="16" height="16">
      <a href="https://github.com/cydonia999/VGGFace2-pytorch" target="_blank" rel="nofollow noopener">GitHub</a>
  </header>
  <article class="onebox-body">
    <img src="https://avatars1.githubusercontent.com/u/28708086?s=400&amp;v=4" class="thumbnail onebox-avatar" width="60" height="60">

<h3><a href="https://github.com/cydonia999/VGGFace2-pytorch" target="_blank" rel="nofollow noopener">cydonia999/VGGFace2-pytorch</a></h3>

<p>VGGFace2-pytorch - PyTorch Face Recognizer based on 'VGGFace2: A dataset for recognising faces across pose and age'</p>


  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
</p>

username: shinx
cooked: <blockquote>
<p>Hi! I hope it’s not too late.<br>
I had found this link pertaining to details regarding vgg-face model along with its weights in the link below. Scroll down to the vgg-face section and download your requirements.</p>
<p><a href="http://www.robots.ox.ac.uk/~albanie/pytorch-models.html" rel="noopener nofollow ugc">http://www.robots.ox.ac.uk/~albanie/pytorch-models.html </a></p>
<p>Hope this helps.</p>
</blockquote>
<p>Hi, is this loadable in the VGG16 torchvision model ?</p>

username: shashankvkt
cooked: <p>I dont think its available as torchvision model. You still have to load the pretrained weights manually.</p>

username: shinx
cooked: <p>I managed to load them manually thanks for your response.</p>

username: shinx
cooked: <pre><code class="lang-auto">def compose_transforms(meta, resize=256, center_crop=True,
                       override_meta_imsize=False):
    """
    Compose preprocessing transforms for model
    The imported models use a range of different preprocessing options,
    depending on how they were originally trained. Models trained in MatConvNet
    typically require input images that have been scaled to [0,255], rather
    than the [0,1] range favoured by PyTorch.
    Args:
        meta (dict): model preprocessing requirements
        resize (int) [256]: resize the input image to this size
        center_crop (bool) [True]: whether to center crop the image
        override_meta_imsize (bool) [False]: if true, use the value of `resize`
           to select the image input size, rather than the properties contained
           in meta (this option only applies when center cropping is not used.
    Return:
        (transforms.Compose): Composition of preprocessing transforms
    """
    normalize = transforms.Normalize(mean=meta['mean'], std=meta['std'])
    im_size = meta['imageSize']
    assert im_size[0] == im_size[1], 'expected square image size'
    if center_crop:
        transform_list = [transforms.Resize(resize),
                          transforms.CenterCrop(size=(im_size[0], im_size[1]))]
    else:
        if override_meta_imsize:
            im_size = (resize, resize)
        transform_list = [transforms.Resize(size=(im_size[0], im_size[1]))]
    transform_list += [transforms.ToTensor()]
    if meta['std'] == [1, 1, 1]:  # common amongst mcn models
        transform_list += [lambda x: x * 255.0]
    transform_list.append(normalize)
    return transforms.Compose(transform_list)
</code></pre>
<p>The model is using the above preprocessing function. What are the transforms actually applied <a href="https://github.com/albanie/pytorch-benchmarks/blob/081e82eb43439ce2821622a6e3d627877caed67a/utils/benchmark_helpers.py#L11" rel="nofollow noopener">here</a> ?</p>
<p>Also why is the following transform used ?</p>
<pre><code class="lang-auto">if meta['std'] == [1, 1, 1]:  # common amongst mcn models
    transform_list += [lambda x: x * 255.0]
</code></pre>

username: apollack
cooked: <p>Hello,<br>
I’ve been trying to use the ResNet50 model from the author site, and downloaded the model/weights. My main use of this is to pass in a batch of images and extract a feature map. I was able to do this successfully with the original pytorch implementation, however, when I do the same setup, I’m thrown an error because of the batch and because of the dimensions. I tried tracing back to see if I could adjust, but I’m unable to find anywhere to work on this. Any ideas? I’m initially using images of shape [B,C,H,W]=[8,3,256,256]. I know ResNet is supposed to be 224x224 but 256 was working, and needed for the size feature map I’m requiring.</p>
<p>It seems like part of the issue might be handling batches itself?</p>
<p>Here is the error:</p>
<pre><code class="lang-auto">Traceback (most recent call last):
  File "C:/Users/a-pollack/Projects/de_ident/de_ident.py", line 27, in &lt;module&gt;
    gen_losses, dis_losses, gen, dis = train_net(num_epochs=5, batch_size=8, lr=1e-4, betas=(0.5, 0.99))
  File "C:\Users\a-pollack\Projects\de_ident\train.py", line 122, in train_net
    z_raw, m, z_masked = gen(data[0])
  File "C:\Users\a-pollack\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\a-pollack\Projects\de_ident\generator.py", line 75, in forward
    face_descriptor = fd_conv2(x)
  File "C:\Users\a-pollack\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\a-pollack\Projects\de_ident\generator_utils.py", line 54, in forward
    x = self.features(x)
  File "C:\Users\a-pollack\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\a-pollack\Anaconda3\lib\site-packages\torch\nn\modules\container.py", line 92, in forward
    input = module(input)
  File "C:\Users\a-pollack\Anaconda3\lib\site-packages\torch\nn\modules\module.py", line 541, in __call__
    result = self.forward(*input, **kwargs)
  File "C:\Users\a-pollack\Anaconda3\lib\site-packages\torch\nn\modules\conv.py", line 345, in forward
    return self.conv2d_forward(input, self.weight)
  File "C:\Users\a-pollack\Anaconda3\lib\site-packages\torch\nn\modules\conv.py", line 342, in conv2d_forward
    self.padding, self.dilation, self.groups)
RuntimeError: Given groups=1, weight of size 256 64 1 1, expected input[8, 256, 64, 64] to have 64 channels, but got 256 channels instead
</code></pre>

username: ptrblck
cooked: <p>The error points to a wrong number of input channels to this particular convolution.<br>
This might be caused by a wrong reshape or by mixing up layers.</p>

username: maro95
cooked: <p>Do we provide images in RGB or BGR format for VGGFace2 resnet50 model?</p>
<p>It doesn’t say anything except that model is trained using the Caffe framework and Caffe uses a BGR color channel scheme for reading image files. It also says that mean image vector is <em>[131.0912, 103.8827, 91.4953]</em> but if see values we can conclude that this mean image vector is in RGB format (there is more red than blue in face images). Does anybody know fo sure what is the truth?</p>

username: shashankvkt
cooked: <p>You are right. I use PIL to read images which is generally in RGB format. In case you use opencv to read images, please consider converting BGR to RGB.</p>