This may also help to learn how to modify layers without changing other layers’ parameters and construct a new model.
    model = models.vgg16(pretrained=True)
    print list(list(model.classifier.children())[1].parameters())
    mod = list(model.classifier.children())
    mod.pop()
    mod.append(torch.nn.Linear(4096, 2))
    new_classifier = torch.nn.Sequential(*mod)
    print list(list(new_classifier.children())[1].parameters())
    model.classifier = new_classifier

Also, you may consider to add pretrained models for VGG, which you may found here:

  
      github.com/pytorch/vision
  
  
    
  
	  
  

  
    
      Pretrained VGG models 546
    

    
      
        opened 
        
          
        
        Jan 18, 2017
      
      

        
          closed 
        
          
        
        Feb 21, 2017
      
        

      
        
          
          jcjohnson
        
      
    
  



  Is there any plan for pretrained VGG models, especially VGG16 or VGG19? These are needed for style transfer; AlexNet and ResNets...





  
  
    
    
  
  


As for finetuning resnet, it is more easy:
model = models.resnet18(pretrained=True)
model.fc = torch.nn.Linear(2048, 2)