Hi,
You need to put the model in inferencing model with model.eva() function to turn off the dropout/batch norm before extracting the feature. And try extracting features with an actual image with imagenet class.

  
    
    
    Using pretrained VGG-16 to get a feature vector from an image vision
  
  
    I even tried declaring the VGG model as follows but it doesn’t work too. This one gives dimensionality errors : 
vgg16_model=models.vgg16(pretrained=True)
# vgg16_model.classifier=vgg16_model.classifier[:-1]
modules_vgg=list(vgg16_model.classifier[:-1])
vgg16_model=nn.Sequential(*modules_vgg)
  


This will result in dimension error because you are re-defining model as following:
Sequential(
  (0): Linear(in_features=25088, out_features=4096, bias=True)
  (1): ReLU(inplace=True)
  (2): Dropout(p=0.5, inplace=False)
  (3): Linear(in_features=4096, out_features=4096, bias=True)
  (4): ReLU(inplace=True)
  (5): Dropout(p=0.5, inplace=False)

so this expects flat input of 25088 dimensional array.