Mona_Jalal:

tf_last_layer_chopped = nn.Sequential(*list(model_conv.children())[:-1])


Hi thanks for the reply.
No, it gives me an error:

from PIL import Image
scaler = transforms.Scale((224, 224))
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
to_tensor = transforms.ToTensor()
img = Image.open('gun.jpg')
image = normalize(to_tensor(scaler(img))).unsqueeze(0).to(device)
my_embedding = torch.zeros(1,512, 1, 1)
tf_last_layer_chopped = nn.Sequential(*list(model_conv.children())[:-1])
print(tf_last_layer_chopped(image))

Error is:
/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torchvision-0.2.1-py3.6.egg/torchvision/transforms/transforms.py:188: UserWarning: The use of the transforms.Scale transform is deprecated, please use transforms.Resize instead.
  "please use transforms.Resize instead.")

---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-54-58cf89cb5ae5> in <module>()
      7 my_embedding = torch.zeros(1,512, 1, 1)
      8 tf_last_layer_chopped = nn.Sequential(*list(model_conv.children())[:-1])
----> 9 print(tf_last_layer_chopped(image))

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    475             result = self._slow_forward(*input, **kwargs)
    476         else:
--> 477             result = self.forward(*input, **kwargs)
    478         for hook in self._forward_hooks.values():
    479             hook_result = hook(self, input, result)

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/modules/container.py in forward(self, input)
     89     def forward(self, input):
     90         for module in self._modules.values():
---> 91             input = module(input)
     92         return input
     93 

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    475             result = self._slow_forward(*input, **kwargs)
    476         else:
--> 477             result = self.forward(*input, **kwargs)
    478         for hook in self._forward_hooks.values():
    479             hook_result = hook(self, input, result)

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/modules/linear.py in forward(self, input)
     53 
     54     def forward(self, input):
---> 55         return F.linear(input, self.weight, self.bias)
     56 
     57     def extra_repr(self):

/scratch/sjn-p3/anaconda/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py in linear(input, weight, bias)
   1024         return torch.addmm(bias, input, weight.t())
   1025 
-> 1026     output = input.matmul(weight.t())
   1027     if bias is not None:
   1028         output += bias

RuntimeError: size mismatch, m1: [512 x 1], m2: [512 x 7] at /opt/conda/conda-bld/pytorch_1535491974311/work/aten/src/THC/generic/THCTensorMathBlas.cu:249