You should have a look here:

  
    
    
    How to extract features of an image from a trained model 
  
  
    Hi all, 
I try examples/imagenet of pytorch. It is awesome and easy to train, but I wonder how can I forward an image and get the feature extraction result? 
After I train with examples/imagenet/main.py, I get model as, 
model_best.pth.tar 
And I load this file with 
model = torch.load('model_best.pth.tar') 
which gives me a dict. How can I use forward method to get a feature (like fc7 layer’s output of Alexnet) of an image with this model?