I have loaded the pre-trained model of vgg19. How to remove the adaptive average pool layer which is present before the classifier?
Asked
Active
Viewed 586 times
2
-
Which framework are you using? tensorflow, keras, pytorch? – mrzo Dec 10 '19 at 14:11
-
@mrzo In pytorch i would like to know how i should be doing this? – i_am_somebody Dec 10 '19 at 16:51
1 Answers
3
If you are using PyTorch and torchVision model, you can disable the use of the last maxpool layer like this -
nn.Sequential(*list(vgg.features._modules.values())[:-1])
Here all the layers are in an array, and not including the last element does the trick.

Solaiman Salvi
- 577
- 4
- 9
-
thanks. but, doing this also removes the max pooling layer. how to retain the max pooling and remove only the adaptive avg pooling layer? – Naveen Reddy Marthala Aug 14 '22 at 07:38
-
and how to drop only the Dense layers at the end retaining both max and adaptive-avg pool layers? – Naveen Reddy Marthala Aug 14 '22 at 07:38
-
my torch version is `1.12.1+cu113` and torchvision's is `0.13.1+cu113` on python 3.7.13 on Ubuntu 18.04. – Naveen Reddy Marthala Aug 14 '22 at 07:38