How to address "UserWarning: ... for interpolate/upsample" issue with Mask R-CNN?

username: KFrank
cooked: <p>Hello Forum!</p>
<p>I am experimenting with torchvision’s <a href="https://pytorch.org/docs/1.7.0/torchvision/models.html#torchvision.models.detection.maskrcnn_resnet50_fpn" rel="noopener nofollow ugc">Mask R-CNN</a> model, and it issues<br>
a UserWarning during the forward pass:</p>
<pre><code class="lang-nohighlight">UserWarning: The default behavior for interpolate/upsample with float
scale_factor changed in 1.6.0 to align with other frameworks/libraries,
and uses scale_factor directly, instead of relying on the computed
output size. If you wish to keep the old behavior, please set
recompute_scale_factor=True. See the documentation of nn.Upsample
for details.
</code></pre>
<p>First, can I safely ignore this warning?</p>
<p>If not, what would be the most practical way to address it?</p>
<p>Some context:</p>
<p>This is something of a known issue.  See for example:</p>
<aside class="onebox githubissue">
  <header class="source">
      <a href="https://github.com/pytorch/vision/issues/2154#issue-608901908" target="_blank" rel="noopener nofollow ugc">github.com/pytorch/vision</a>
  </header>
  <article class="onebox-body">
    <div class="github-row">
  <div class="github-icon-container" title="Issue">
	  <svg width="60" height="60" class="github-icon" viewBox="0 0 14 16" aria-hidden="true"><path d="M7 2.3c3.14 0 5.7 2.56 5.7 5.7s-2.56 5.7-5.7 5.7A5.71 5.71 0 0 1 1.3 8c0-3.14 2.56-5.7 5.7-5.7zM7 1C3.14 1 0 4.14 0 8s3.14 7 7 7 7-3.14 7-7-3.14-7-7-7zm1 3H6v5h2V4zm0 6H6v2h2v-2z"></path></svg>
  </div>

  <div class="github-info-container">
    <h4>
      <a href="https://github.com/pytorch/vision/issues/2154#issue-608901908" target="_blank" rel="noopener nofollow ugc">"This overload of nonzero is deprecated"</a>
    </h4>

    <div class="github-info">
      <div class="date">
        opened <span class="discourse-local-date" data-format="ll" data-date="2020-04-29" data-time="09:16:34" data-timezone="UTC">09:16AM - 29 Apr 20 UTC</span>
      </div>

        <div class="date">
          closed <span class="discourse-local-date" data-format="ll" data-date="2020-09-24" data-time="09:19:20" data-timezone="UTC">09:19AM - 24 Sep 20 UTC</span>
        </div>

      <div class="user">
        <a href="https://github.com/LexRillo" target="_blank" rel="noopener nofollow ugc">
          <img alt="LexRillo" src="https://avatars3.githubusercontent.com/u/26965905?v=4" class="onebox-avatar-inline" width="20" height="20">
          LexRillo
        </a>
      </div>
    </div>
  </div>
</div>

<div class="github-row">
  <p class="github-content">🐛 Bug
A change in torch\nn\functional might have change usability of the nonzero function used in fasterrcnn_resnet50_fpn. This produces a warning and...</p>
</div>

<div class="labels">
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">enhancement</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">help wanted</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">high priority</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">module: models</span>
    <span style="display:inline-block;margin-top:2px;background-color: #B8B8B8;padding: 2px;border-radius: 4px;color: #fff;margin-left: 3px;">topic: object detection</span>
</div>

  </article>
  <div class="onebox-metadata">
    
    
  </div>
  <div style="clear: both"></div>
</aside>

<p>(Here, the “interpolate/upsample” issue is mentioned along side the<br>
more central “overload of nonzero” issue.)</p>
<p>I see this issue running, for example, pytorch/torchvision version<br>
1.8.0.dev20201203/0.9.0.dev20201203 (as well as on a stable<br>
version).</p>
<p>Note that <code>recompute_scale_factor</code> isn’t mentioned in the<br>
documentation for <a href="https://pytorch.org/docs/1.7.0/generated/torch.nn.Upsample.html" rel="noopener nofollow ugc">nn.Upsample</a>, although it is in<br>
<a href="https://pytorch.org/docs/1.7.0/nn.functional.html#torch.nn.functional.interpolate" rel="noopener nofollow ugc">nn.functional.interpolate()</a>.</p>
<p>Thanks for any advice.</p>
<p>K. Frank</p>

username: ptrblck
cooked: <p>I’ve seen the same warning and was also wondering, if the code should be adapted.</p>
<p>CC <a class="mention" href="/u/fmassa">@fmassa</a><br>
Should the old behavior be used for the interpolation or is the new one alright?</p>