Pytorch load model
I used tensorflow some days ago. To build conv layers with fixed weights is easy, just pass the weight kernel to conv2d(). And it is convenient to load pretrained models such as VGG19. But I found it did't work that way using pytorch, because conv2d() doesn't accept an explicit kernel but a kernel size. So I wonder if there is any possibility that we can reuse the weights in VGG19 by simply passing it to a method like conv2d(). Any reply will be appreciated.

I can see that you have 2 questions . How to use a pre-trained model like VGG in pyTorch and how to set the weights for a particular layer like nn.conv2d().

For creating a pretrained Vgg model you can use the below code.

from torchvision import models    
model_vgg = models.vgg16(pretrained=True)
for param in model_vgg.parameters():
    param.requires_grad = False


In PyTorch you implement neural network subclassing nn.Module which contains the parameters() function which returns all the weights associated with the network.

Setting the weights of a particular layer .

decoder = nn.Linear(10, 100) 
decoder.weight = #Do anything which is valid.


You can check my code here to know more on how to use a trained model.
