l would like to use ReNet-152 as a feature extractor (for new input images) from a specific layers let’s say layer 1, 18, 52, 97, 123 and 149.
The following code allows to extract features from last hidden layer (fully connected)
My question is how can l get access to specific layers and extract features from the specified layer ?
import numpy as np
import torch.nn as nn
import torchvision.models as models
from torch.autograd import Variable
from torchvision.transforms import ToTensor
from PIL import Image
import glob as glob
resnet152 = models.resnet152(pretrained=True) modules=list(resnet152.children())[:-1] resnet152=nn.Sequential(*modules)