About torch.nn.Upsample?

MartinZhang: <p>Dear,</p>
<p>I realize the interp with pytorch like this <code>O(n^2)</code>：</p>
<pre><code class="lang-auto">import torch

def bilinear_interpolation(tensor_data, out_dim):
    batch, channels, src_h,src_w = tensor_data.shape
    dst_h,dst_w = out_dim[1],out_dim[0]

    if src_h == dst_h and src_w == dst_w:
        return tensor_data.copy()

    dst_img = torch.zeros((batch, channels, dst_h,dst_w))

    scale_x,scale_y = float(src_w)/dst_w,float(src_h)/dst_h

    for h in range(dst_h):
        for w in range (dst_w):
                    .... ....
    return dst_img
</code></pre>
<p>I have a test for:  tensor_size = (1, 3, 224, 224) interp into tensor_size = (1, 3, 448, 448)</p>
<p>it spend the time about <code>14s</code></p>
<p>but  when I use the torch.nn.Upsample , it spend time about<code> 0.003s.</code></p>
<p>Why? I think maybe it’s affected by the cycle.</p>
<p>But, I am not find the source code about torch.nn.Upsample.</p>
<aside class="onebox githubblob" data-onebox-src="https://github.com/pytorch/pytorch/blob/0b2dc3b3ac7a49e100225994f03f0c41d701d04e/torch/ao/nn/quantized/functional.py#L318">
  <header class="source">

      <a href="https://github.com/pytorch/pytorch/blob/0b2dc3b3ac7a49e100225994f03f0c41d701d04e/torch/ao/nn/quantized/functional.py#L318" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/pytorch/blob/0b2dc3b3ac7a49e100225994f03f0c41d701d04e/torch/ao/nn/quantized/functional.py#L318" target="_blank" rel="noopener nofollow ugc">pytorch/pytorch/blob/0b2dc3b3ac7a49e100225994f03f0c41d701d04e/torch/ao/nn/quantized/functional.py#L318</a></h4>



    <pre class="onebox"><code class="lang-py">
      <ol class="start lines" start="308" style="counter-reset: li-counter 307 ;">
          <li>    if input.ndim != 5:</li>
          <li>        raise ValueError("Input shape must be `(N, C, D, H, W)`!")</li>
          <li>    stride = _triple(stride)</li>
          <li>    padding = _triple(padding)</li>
          <li>    dilation = _triple(dilation)</li>
          <li>
          </li>
<li>    packed_params = torch.ops.quantized.conv3d_prepack(</li>
          <li>        weight, bias, stride, padding, dilation, groups)</li>
          <li>    return torch.ops.quantized.conv3d(input, packed_params, scale, zero_point)</li>
          <li>
          </li>
<li class="selected">def interpolate(input, size=None, scale_factor=None, mode='nearest', align_corners=None):</li>
          <li>    r"""Down/up samples the input to either the given :attr:`size` or the given</li>
          <li>    :attr:`scale_factor`</li>
          <li>
          </li>
<li>    See :func:`torch.nn.functional.interpolate` for implementation details.</li>
          <li>
          </li>
<li>    The input dimensions are interpreted in the form:</li>
          <li>    `mini-batch x channels x [optional depth] x [optional height] x width`.</li>
          <li>
          </li>
<li>    .. note:: The input quantization parameters propagate to the output.</li>
          <li>
      </li>
</ol>
    </code></pre>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>Who can help me?</p>
<p>I want to rewrite torch.nn.Upsample for my project.</p>
<p><strong>Thank you，Best Wish!!</strong></p>