Pytorch, Pre-trained model: How to use feature and classifier at the same time
I'm using vgg16 extracting image feature vector. I want to get 114096 vector from the 2nd-to-last layer.
My code:
def get_model():
model = models.vgg16(pretrained=True)#.features[:].classifier[:4]
model = model.eval()
# model.cuda() # send the model to GPU, DO NOT include this line if you haven't a GPU
return model
But I can only get 111000 vector from the last layer.
I know how to use feathers
and classifier
, but I don't know how to use them at the same time.
use classifier only:
use feathers only:
use them at the same time:
log:
Traceback (most recent call last):
File "/mnt/c/Users/sunji/PycharmProjects/image_cluster_pytorch/main.py", line 7, in <module>
model = calc.get_model()
File "/mnt/c/Users/sunji/PycharmProjects/image_cluster_pytorch/imagecluster/calc.py", line 17, in get_model
model = models.vgg16(pretrained=True).features[:].classifier[:4]
File "/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py", line 771, in __getattr__
raise ModuleAttributeError("'{}' object has no attribute '{}'".format(
torch.nn.modules.module.ModuleAttributeError: 'Sequential' object has no attribute 'classifier'
from Recent Questions - Stack Overflow https://ift.tt/2FUXOsJ
https://ift.tt/34nhNJS
Comments
Post a Comment