Pytorch Tracer Warnings

username: eastchun
cooked: <p>While I am running the pytorch codes, I keep getting the tracer warnings for the codes below. It makes me confused what is being converted into a python index or python boolean and also why index is out of bounds, and I don’t know where to start (I am new in pytorch, btw).</p>
<pre><code class="lang-auto">def concatenate_input_noise_map(input, noise_sigma):

# Args:
# input: batch containing CxHxW images
# noise_sigma: the value of the pixels of the Cx(H/2)x(W/2) noise map

    N, C, H, W = input.size()
    dtype = input.type()
    sca = 2
    sca2 = sca*sca
    Cout = sca2*C
    Hout = H//sca
    Wout = W//sca
    idxL = [[0, 0], [0, 1], [1, 0], [1, 1]]

    ### Fill the downsampled image with zeros
    if 'cuda' in dtype:
       downsampledfeatures = torch.cuda.FloatTensor(N, Cout, Hout, Wout).fill_(0)  #(A)
    else:
       downsampledfeatures = torch.FloatTensor(N, Cout, Hout, Wout).fill_(0)

    ### Build the Cx(H/2)x(W/2) noise map (Note. noise_sigma is a list of length batch_size)
    noise_map = noise_sigma.view(N, 1, 1, 1).repeat(1, C, Hout, Wout)

    ### Populate output
    for idx in range(sca2):
       downsampledfeatures[:, idx:Cout:sca2, :, :] = input[:, :, idxL[idx][0]::sca, idxL[idx][1]::sca]  #(B)

    ### Concatenate de-interleaved mosaic with noise map
    return torch.cat((noise_map, downsampledfeatures), 1)


class UpSampleFeaturesFunction(Function):

    @staticmethod
    def forward(ctx, input):
      N, Cin, Hin, Win = input.size()
      dtype = input.type()
      sca = 2
      sca2 = sca*sca
      Cout = Cin//sca2
      Hout = Hin*sca
      Wout = Win*sca
      idxL = [[0, 0], [0, 1], [1, 0], [1, 1]]

      assert (Cin%sca2 == 0), 'Invalid input dimensions: # of channels should be divisible by 4'  #(C)

      result = torch.zeros((N, Cout, Hout, Wout)).type(dtype)

      for idx in range(sca2):
        result[:, :, idxL[idx][0]::sca, idxL[idx][1]::sca] = input[:, idx:Cin:sca2, :, :]  #(D)

      return result
</code></pre>
<blockquote>
<p>Warning for the above lines (A) &amp; (B):</p>
</blockquote>
<p>TracerWarning: Converting a tensor to a Python index might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!</p>
<blockquote>
<p>Warning for the above line ( C):</p>
</blockquote>
<p>TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!</p>
<p>*Note. Cin is always a multiple of 4 (but I got assert warning).</p>
<blockquote>
<p>Warning for the above line (D):</p>
</blockquote>
<p>Converting a tensor to a Python index might cause the trace to be incorrect. We can’t record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!</p>
<p>ERROR:utils:Couldn’t log results: index 1 is out of bounds for dimension 0 with size 1</p>

username: 111257
cooked: <p>Hello，I’ve been having this problem lately，How did you solve it？</p>