Consider the following code which will print the modules of the faster_rcnn model in PyTorch.
model_fastercnn = torchvision.models.detection.fasterrcnn_resnet50_fpn(pretrained=True) 
modules_2 = list(model_fastercnn.children())
for iter, module in enumerate(modules_2):
    print("###### {} ######".format(iter))
    print(module) 

Here is the last module which printed by previous code.
###### 3 ######
RoIHeads(
  (box_roi_pool): MultiScaleRoIAlign()
  (box_head): TwoMLPHead(
    (fc6): Linear(in_features=12544, out_features=1024, bias=True)
    (fc7): Linear(in_features=1024, out_features=1024, bias=True)
  )
  (box_predictor): FastRCNNPredictor(
    (cls_score): Linear(in_features=1024, out_features=91, bias=True)
    (bbox_pred): Linear(in_features=1024, out_features=364, bias=True)
  )
)

Now let’s say we want to use the output of “fc7” (RoIHeads->box_head->fc7) as input to another custom layers, for example, one Linear 1024 -> 512, also want to use the pre-trained weight until the fc7 and just train the weights of the last added layer for some loss function. Since the last module is wrapped with the class is there any way for doing so?
I bring up the last sentence since for example consider the resnet152, by printing the modules, I learn that It contains “9” layers and the last layer is an FC, I omit the last layer and build another Sequential network then added another layer and train the model using the only parameter of the last layer.