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

username: Jaspreet_Singh_Kalsi
cooked: <p>I was following this tutorial  <a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html#modifying-the-model-to-add-a-different-backbone" rel="noopener nofollow ugc">Modifying the model to add a different backbone</a>. When I replace the mobilenet_v2 model with inception_v3, the code does not work and  gives the following error:</p>
<pre><code class="lang-auto">  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'
</code></pre>
<p>I am using the following environment:</p>
<ul>
<li>Ubuntu 18.04.4 LTS</li>
<li>CUDA Version: 10.2</li>
<li>Python: 3.8.6</li>
<li>Pytorch: 1.7.0</li>
</ul>
<p>It will be great if someone can help me in resolving this issue.<br>
Thanks</p>

username: ptrblck
cooked: <p>In the example only the <code>.features</code> branch of the model is passed to the <code>FasterRCNN</code> model, while it seems you are passing the complete Inception model to it, as the error points to <code>InceptionOutput</code>.<br>
Could you try to pass just the feature extractor part to <code>FasterRCNN</code> as done in the tutorial?</p>

username: Jaspreet_Singh_Kalsi
cooked: <p>It seems to me there is no feature extractor part exist in <a href="https://pytorch.org/docs/stable/_modules/torchvision/models/inception.html#inception_v3" rel="noopener nofollow ugc">inception_v3</a> as it gives  the following error:</p>
<pre><code class="lang-auto">    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'
</code></pre>

username: ptrblck
cooked: <p>That’s right and in that case you would need to create the feature extractor manually e.g. by replacing the <code>self.fc</code> with an <code>nn.Identity</code> module or by wrapping the <a href="https://github.com/pytorch/vision/blob/d3d393672b877f80fedd2d11de6b84fb19599c2e/torchvision/models/inception.py#L142-L188">feature layers</a> in an own module.</p>