-1

I have a bunch of medical images and I want to do some feature extraction on them. To do that, I intend to use pretrained CNN VGG16. It has a list of target classes which is consists of name of the ordinary objects. How can I change it to do feature extraction instead of object classifying? I mean what change I should perform on its architecture?

Elessar
  • 93
  • 2
  • 11

1 Answers1

0

It depends on language and framework you are using, you should specify such things in your questions. In Pytorch, you can do it this way:

original_model = models.vgg19(pretrained=True).eval()
feature_extractor = nn.Sequential(*list(original_model.features.children()))
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
                                 std=[0.229, 0.224, 0.225])
img = io.imread("some_image.png")
img = transform.resize(img, (224, 224), order=3)
img = torch.from_numpy(img)
img = img.permute(2, 0, 1)
img = normalize(img)
img = img.unsqueeze(0)
with torch.no_grad():
    features = feature_extractor.forward(img)

Note the scaling and normalization, vgg works best for 224x224 normalized (with values from code).

S.Piechaczek
  • 207
  • 2
  • 5