Listing the layers in a pre-built model, and adding one

Good day.

  1. How do I view the layers in a model such as

model = torch.hub.load(‘pytorch/vision:v0.10.0’, ‘resnet101’, pretrained=True)

  1. How would I add or change the final layer of this model?

Thanks.

  1. You can directly print the model to see all registered layers. Alternatively, you can also iterate the .modules().

  2. In the previous step you will see the final layer definition as self.fc and could replace it with your custom layer.

To add on to what patrick said, I have done this using add_module, not sure if it is the best way, however