Hi everyone! I am trying to do what I did (see below) in VGG16 but in ResNet and GoogleNet. I basically want to remove some of the last layers of these models. I get an error. I would like to use them for feature extraction. I have read that the error could be located in the flatten, but I honestly do not know how to implement it. Please, could anyone help me? Thanks in advance.
class resnet18_fe(nn.Module):
            def __init__(self):
                super(resnet18_fe, self).__init__()
                self.features = nn.Sequential(
                    # removing the last convolutional layer
                    *list(original_model_resnet.features.children())[:-3]
                )
            def forward(self, x):
                x = self.features(x)
                return x

model_3 = resnet18_fe().to(device=device)

The error I get is:

AttributeError                            Traceback (most recent call last)
 in ()
10                 return x
11
—> 12 model_3 = resnet18_fe().to(device=device)
13
14 print(model_3)
1 frames
/usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in getattr(self, name)
946                 return modules[name]
947         raise AttributeError("’{}’ object has no attribute ‘{}’".format(
 → 948             type(self).name, name))
949
950     def setattr(self, name: str, value: Union[Tensor, ‘Module’]) → None:
AttributeError: ‘ResNet’ object has no attribute ‘features’