Using pretrained VGG-16 to get a feature vector from an image

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)