Labels out of range torchvision.models.detection.fasterrcnn_resnet50_fpn

sal: <p>The vision modelzoo  <a href="https://pytorch.org/docs/stable/torchvision/models.html#torchvision.models.detection.fasterrcnn_resnet50_fpn" rel="noopener nofollow ugc">Fasterrcnn doc</a> says the following :</p>
<p>During training, the model expects both the input tensors, as well as a targets dictionary, containing:</p>
<blockquote>
<ul>
<li>boxes ( <code>Tensor[N, 4]</code> ): the ground-truth boxes in  <code>[x0, y0, x1, y1]</code>  format, with values between  <code>0</code> and  <code>H</code>  and  <code>0</code>  and  <code>W</code></li>
</ul>
</blockquote>
<p>These are my sample  inputs  &lt;H,W, [x0,y0,x1,y1]&gt;:</p>
<pre><code class="lang-auto">124 898 tensor([21.,  0., 88., 46.], device='cuda:0')
124 898 tensor([45., 51., 89., 98.], device='cuda:0')
124 898 tensor([ 50., 132.,  76., 183.], device='cuda:0')
124 898 tensor([ 63., 227.,  63., 349.], device='cuda:0')
124 898 tensor([ 63., 795.,  63., 870.], device='cuda:0')
124 898 tensor([  0., 229.,  50., 261.], device='cuda:0')
124 898 tensor([ 11., 269.,  49., 308.], device='cuda:0')
124 898 tensor([ 16., 314.,  50., 349.], device='cuda:0')
124 898 tensor([ 72., 259., 122., 280.], device='cuda:0')
124 898 tensor([ 72., 290., 123., 324.], device='cuda:0')
124 898 tensor([ 43., 389.,  89., 419.], device='cuda:0')
124 898 tensor([ 43., 426.,  89., 470.], device='cuda:0')
124 898 tensor([ 55., 531.,  71., 584.], device='cuda:0')
124 898 tensor([ 45., 619.,  89., 666.], device='cuda:0')
124 898 tensor([ 50., 700.,  76., 751.], device='cuda:0')
124 898 tensor([  0., 815.,  50., 847.], device='cuda:0')
124 898 tensor([ 72., 798., 123., 827.], device='cuda:0')
124 898 tensor([ 72., 835., 123., 867.], device='cuda:0')
124 898 tensor([ 78., 887.,  89., 897.], device='cuda:0')
</code></pre>
<p>still I get the error ;</p>
<pre><code class="lang-auto">/opt/conda/conda-bld/pytorch_1556653215914/work/aten/src/THCUNN/ClassNLLCriterion.cu:105: void cunn_ClassNLLCriterion_updateOutput_kernel(Dtype *, Dtype *, Dtype *, long *, Dtype *, int, int, int, int, long) [with Dtype = float, Acctype = float]: block: [0,0,0], thread: [0,0,0] Assertion `t &gt;= 0 &amp;&amp; t &lt; n_classes` failed.
</code></pre>
<p><code>File "/anaconda2/envs/py/lib/python3.7/site-packages/torchvision/models/detection/roi_heads.py", line 34, in fastrcnn_loss</code><br>
<code> sampled_pos_inds_subset = torch.nonzero(labels &gt; 0).squeeze(1)</code></p>
<p><code>RuntimeError: copy_if failed to synchronize: device-side assert triggered</code></p>
<p>Am I missing something ? If it is not the actual arget values which are out of range then what else could cause this error ?</p>

radeeplearning: <p>I have a similar issue, I was wondering if you solved this?</p>

sal: <p>The docs have an error the H and W are opposite.<br>
Follow this tutorial : <a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html" class="inline-onebox" rel="noopener nofollow ugc">TorchVision Object Detection Finetuning Tutorial — PyTorch Tutorials 2.1.1+cu121 documentation</a></p>
<ul>
<li><code>boxes (FloatTensor[N, 4])</code> : the coordinates of the  <code>N</code>  bounding boxes in  <code>[x0, y0, x1, y1]</code>  format, ranging from  <code>0</code>  to  <code>W</code> and  <code>0</code>  to  <code>H</code></li>
</ul>
<p>basically check your data for all bbox annotation conforming to :<br>
0&lt;= x0, x1 &lt;= W<br>
x0 &lt; x1<br>
0&lt;=y0, y1 &lt;= H<br>
y0 &lt; y1</p>
<p>My error was some boxes had x0=x1 / y0=y1<br>
meaning the bbox has 0 height or 0 width like</p>
<aside class="quote no-group quote-modified" data-username="sal" data-post="1" data-topic="52452">
<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/sal/48/4523_2.png" class="avatar"> sal:</div>
<blockquote>
<p>124 898 tensor([ 63., 227., 63., 349.], device=‘cuda:0’)</p>
</blockquote>
</aside>