How can i extract the features from grayscale images

I need to extract features from medical images using Pytorch but the features I need are before the final layer for the classification … i used like this

 model = VGG16()
 model = models.Model(inputs=model.inputs, outputs=model.layers[-2].output)

does that right or the medical needs another way, please ?

PyTorch does not identify specific image modalities, eg medical image or natural images.

Basically, all you need is a 3-channel tensor, no matter what it contains.

But you may finetune on your own data before extracting features I guess.

1 Like

Hello,
I believe what you wanted is just the convolutional part of VGG16.
This is the base of style-transfer problem in ML.
https://pytorch.org/tutorials/advanced/neural_style_tutorial.html#:~:text=%23%20desired%20depth%20layers,style_losses%2C%20content_losses
Under this link you will find code which extracts tensors of features on different lvls of the network. So effectively you just remove the part of the network you don’t need.

Thanks a lot, i will see it now but excuse me can you help in this