Hi. I want to split a pretrained model, Torchvision’s faster RCNN to be particular, into two parts. However, the model is fully sequential.
FasterRCNN(
  (transform): GeneralizedRCNNTransform(
      Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
      Resize(min_size=(800,), max_size=1333, mode='bilinear')
  )
  (backbone): BackboneWithFPN(
    (body): IntermediateLayerGetter(
      (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
      (bn1): FrozenBatchNorm2d(64, eps=0.0)
      (relu): ReLU(inplace=True)
      (maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
     # This is where I wanna split the model.

Currently, my very hacky solution is to go layer-by-layer and get the sub modules (children) by hand.
transform = model.get_submodule(target = 'transform')
backbone = model.get_submodule(target = 'backbone')
backbone_body = backbone.get_submodule(target = 'body')
body_layers = list(backbone_body.children())[0:4]

new_model = torch.nn.Module()
new_model.add_module('transform', transform)
new_backbone = torch.nn.Module()
new_backbone_body = torch.nn.ModuleDict()
layer_names = ['conv1', 'bn1', 'relu', 'maxpool']
for l_name, layer in zip(layer_names, body_layers):
    new_backbone_body.add_module(l_name, layer)

new_backbone.add_module('body', new_backbone_body)
new_model.add_module('backbone', new_backbone)

which gave me this new model:
Module(
  (transform): GeneralizedRCNNTransform(
      Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
      Resize(min_size=(800,), max_size=1333, mode='bilinear')
  )
  (backbone): Module(
    (body): ModuleDict(
      (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False)
      (bn1): FrozenBatchNorm2d(64, eps=0.0)
      (relu): ReLU(inplace=True)
      (maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False)
    )
  )
)

When I loaded the pretrained weights into the new model with strict = True, I didnt find any of the layers that I had just manually added in the error message. Do you think that this was successful? Or do you think there could be any potential issues during deployment?
Any thought would be much appreciated.
Thanks,