Can any one help me about this error

username: Manoj_Reddy
cooked: <h2>
<a name="epoch-024-1" class="anchor" href="#epoch-024-1"></a>Epoch 0/24</h2>
<hr>
<p>ValueError                                Traceback (most recent call last)<br>
~\AppData\Local\Temp/ipykernel_17472/3334111515.py in <br>
----&gt; 1 model = train_model(model, criterion, optimizer_ft, exp_lr_scheduler,num_epochs=25)</p>
<p>~\AppData\Local\Temp/ipykernel_17472/1055981521.py in train_model(model, criterion, optimizer, scheduler, num_epochs)<br>
30                 # track history if only in train<br>
31                 with torch.set_grad_enabled(phase == ‘train’):<br>
—&gt; 32                     result = model(inputs)<br>
33                     _, preds = torch.max(outputs, 0)<br>
34                     loss = criterion(outputs, labels)</p>
<p>C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\modules\module.py in _call_impl(self, *input, **kwargs)<br>
1100         if not (self._backward_hooks or self._forward_hooks or self._forward_pre_hooks or _global_backward_hooks<br>
1101                 or _global_forward_hooks or _global_forward_pre_hooks):<br>
 → 1102             return forward_call(*input, **kwargs)<br>
1103         # Do not call functions when jit is used<br>
1104         full_backward_hooks, non_full_backward_hooks = [], []</p>
<p>C:\ProgramData\Anaconda3\lib\site-packages\torchvision\models\detection\generalized_rcnn.py in forward(self, images, targets)<br>
55         “”"<br>
56         if self.training and targets is None:<br>
—&gt; 57             raise ValueError(“In training mode, targets should be passed”)<br>
58         if self.training:<br>
59             assert targets is not None</p>
<p>ValueError: In training mode, targets should be passed</p>

username: Matias_Vasquez
cooked: <p>Here is the link to the source code for the GeneralizedRCNN.</p><aside class="onebox githubblob" data-onebox-src="https://github.com/pytorch/vision/blob/d59398b5655cf7f9a4a6e3c4c89721fab5cc2bb5/torchvision/models/detection/generalized_rcnn.py#L46">
  <header class="source">

      <a href="https://github.com/pytorch/vision/blob/d59398b5655cf7f9a4a6e3c4c89721fab5cc2bb5/torchvision/models/detection/generalized_rcnn.py#L46" target="_blank" rel="noopener nofollow ugc">github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://github.com/pytorch/vision/blob/d59398b5655cf7f9a4a6e3c4c89721fab5cc2bb5/torchvision/models/detection/generalized_rcnn.py#L46" target="_blank" rel="noopener nofollow ugc">pytorch/vision/blob/d59398b5655cf7f9a4a6e3c4c89721fab5cc2bb5/torchvision/models/detection/generalized_rcnn.py#L46</a></h4>



    <pre class="onebox">      <code class="lang-py">
        <ol class="start lines" start="36" style="counter-reset: li-counter 35 ;">
            <li>    self._has_warned = False</li>
            <li>
            </li>
<li>@torch.jit.unused</li>
            <li>def eager_outputs(self, losses, detections):</li>
            <li>    # type: (Dict[str, Tensor], List[Dict[str, Tensor]]) -&gt; Union[Dict[str, Tensor], List[Dict[str, Tensor]]]</li>
            <li>    if self.training:</li>
            <li>        return losses</li>
            <li>
            </li>
<li>    return detections</li>
            <li>
            </li>
<li class="selected">def forward(self, images, targets=None):</li>
            <li>    # type: (List[Tensor], Optional[List[Dict[str, Tensor]]]) -&gt; Tuple[Dict[str, Tensor], List[Dict[str, Tensor]]]</li>
            <li>    """</li>
            <li>    Args:</li>
            <li>        images (list[Tensor]): images to be processed</li>
            <li>        targets (list[Dict[str, Tensor]]): ground-truth boxes present in the image (optional)</li>
            <li>
            </li>
<li>    Returns:</li>
            <li>        result (list[BoxList] or dict[Tensor]): the output from the model.</li>
            <li>            During training, it returns a dict[Tensor] which contains the losses.</li>
            <li>            During testing, it returns list[BoxList] contains additional fields</li>
        </ol>
      </code>
    </pre>



  </article>

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

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

<p>If you go down to line 60, you will see that when in <code>training mode</code> you need to pass not only the image, but also the targets.</p>
<p>From the error that you have posted, it seems you are only passing the variable <code>inputs</code> forward. If this variable has the images and targets, then you should separate them into two vars.</p>
<p><a href="https://pytorch.org/tutorials/intermediate/torchvision_tutorial.html#testing-forward-method-optional" rel="noopener nofollow ugc">Here</a> is a tutorial example with FasterRCNN, where they also pass the targets in training, but not in evaluation mode.</p>
<p>Hope this helps.</p>