Getting an error when modifying the faster_rcnn model to add inception_v3 backbone model

I was following this tutorial Modifying the model to add a different backbone. When I replace the mobilenet_v2 model with inception_v3, the code does not work and gives the following error:

  File "/home/gpu-user/projects/building-outline-detection/src/models/faster_rcnn/vision/engine.py", line 46, in train_one_epoch
    loss_dict = model(images, targets)
  File "/home/gpu-user/miniconda3/envs/faster_rcnn/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/gpu-user/miniconda3/envs/faster_rcnn/lib/python3.8/site-packages/torchvision/models/detection/generalized_rcnn.py", line 99, in forward
    proposals, proposal_losses = self.rpn(images, features, targets)
  File "/home/gpu-user/miniconda3/envs/faster_rcnn/lib/python3.8/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/home/gpu-user/miniconda3/envs/faster_rcnn/lib/python3.8/site-packages/torchvision/models/detection/rpn.py", line 330, in forward
    features = list(features.values())
AttributeError: 'InceptionOutputs' object has no attribute 'values'

I am using the following environment:

  • Ubuntu 18.04.4 LTS
  • CUDA Version: 10.2
  • Python: 3.8.6
  • Pytorch: 1.7.0

It will be great if someone can help me in resolving this issue.
Thanks

In the example only the .features branch of the model is passed to the FasterRCNN model, while it seems you are passing the complete Inception model to it, as the error points to InceptionOutput.
Could you try to pass just the feature extractor part to FasterRCNN as done in the tutorial?

It seems to me there is no feature extractor part exist in inception_v3 as it gives the following error:

    backbone = backbone_models[BACKBONE_MODEL_NAME]['model'](pretrained=True).features
  File "/home/gpu-user/miniconda3/envs/faster_rcnn/lib/python3.8/site-packages/torch/nn/modules/module.py", line 778, in __getattr__
    raise ModuleAttributeError("'{}' object has no attribute '{}'".format(
torch.nn.modules.module.ModuleAttributeError: 'Inception3' object has no attribute 'features'

That’s right and in that case you would need to create the feature extractor manually e.g. by replacing the self.fc with an nn.Identity module or by wrapping the feature layers in an own module.