If k = 0 and self.featmap_names=[0] shouldn't k in self.featmap_names be True? Getting False

T33K3Y: <p>Hello People,</p>
<p>i’m trying to get Faster Rcnn to run according to the tutorial given in</p><aside class="onebox allowlistedgeneric">
  <header class="source">
      <a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html#modifying-the-model-to-add-a-different-backbone" target="_blank" rel="noopener nofollow ugc">pytorch.org</a>
  </header>
  <article class="onebox-body">
    <img src="" class="thumbnail" width="" height="">

<h3><a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html#modifying-the-model-to-add-a-different-backbone" target="_blank" rel="noopener nofollow ugc">TorchVision Object Detection Finetuning Tutorial — PyTorch Tutorials 1.7.1...</a></h3>



  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>
<p>
.<br>
I get</p>
<p>Traceback (most recent call last):<br>
File “/home/hmmmm/PycharmProjects/pythonProject3/identitymodul.py”, line 296, in <br>
out = model(images)<br>
File “/home/hmmmm/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py”, line 722, in _call_impl<br>
result = self.forward(*input, **kwargs)<br>
File “/home/hmmmm/anaconda3/lib/python3.8/site-packages/torchvision/models/detection/generalized_rcnn.py”, line 99, in forward<br>
detections, detector_losses = self.roi_heads(features, proposals, images.image_sizes, targets)<br>
File “/home/hmmmm/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py”, line 722, in _call_impl<br>
result = self.forward(*input, **kwargs)<br>
File “/home/hmmmm/anaconda3/lib/python3.8/site-packages/torchvision/models/detection/roi_heads.py”, line 751, in forward<br>
box_features = self.box_roi_pool(features, proposals, image_shapes)<br>
File “/home/hmmmm/anaconda3/lib/python3.8/site-packages/torch/nn/modules/module.py”, line 722, in _call_impl<br>
result = self.forward(*input, **kwargs)<br>
File “/home/hmmmm/anaconda3/lib/python3.8/site-packages/torchvision/ops/poolers.py”, line 198, in forward<br>
self.setup_scales(x_filtered, image_shapes)<br>
File “/home/hmmmm/anaconda3/lib/python3.8/site-packages/torchvision/ops/poolers.py”, line 162, in setup_scales<br>
lvl_min = -torch.log2(torch.tensor(scales[0], dtype=torch.float32)).item()<br>
IndexError: list index out of range</p>
<p>as an error, so i tried to debug and found out that “x_filtered” is empty and this is caused by this for-loop</p>
<pre><code>    for k, v in x.items():
        if k in self.featmap_names:
            x_filtered.append(v)
</code></pre>
<p>so i have added some prints to better understand what was happening</p>
<pre><code>    for k, v in x.items():

        print('k')
        print(k)
        print(self.featmap_names)
        print(k in self.featmap_names)
        if k in self.featmap_names:
            x_filtered.append(v)
            print('testo')
</code></pre>
<p>and got the following output:</p>
<p>k<br>
0<br>
[0]<br>
False</p>
<p>As I see it this False should be true, but i guess i am not seeing something.</p>
<p>Would be thankful for any help.</p>

T33K3Y: <p>Got a solution here:</p>
<aside class="quote quote-modified" data-post="5" data-topic="79834">
  <div class="title">
    <div class="quote-controls"></div>
    <img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/jimmy_hall/48/13872_2.png" class="avatar">
    <a href="https://discuss.pytorch.org/t/index-error-using-custom-backbone-on-fasterrcnn/79834/5">Index error using custom backbone on FasterRCNN</a> <a class="badge-category__wrapper " href="/c/vision/5"><span data-category-id="5" data-drop-close="true" class="badge-category " title="Topics related to either pytorch/vision or vision research related topics"><span class="badge-category__name">vision</span></span></a>
  </div>
  <blockquote>
    I got the same error following the tutorial exactly, but the FasterRCNN documentation: 
<a href="https://github.com/pytorch/vision/blob/master/torchvision/models/detection/faster_rcnn.py" rel="noopener nofollow ugc">https://github.com/pytorch/vision/blob/master/torchvision/models/detection/faster_rcnn.py</a> 
suggests that  the featmap_names in the MultiScaleROIAlign should be a character, ‘0’, not an integer. I replaced 
roi_pooler = torchvision.ops.MultiScaleRoIAlign(featmap_names=[0],
                                                output_size=7,
                                                sampling_ratio=2)

with 
roi…
  </blockquote>
</aside>