class_docstr: L2 loss with margin.
  
  Args:
      neg_pos_ub (int, optional): The upper bound of negative to positive
          samples in hard mining. Defaults to -1.
      pos_margin (float, optional): The similarity margin for positive
          samples in hard mining. Defaults to -1.
      neg_margin (float, optional): The similarity margin for negative
          samples in hard mining. Defaults to -1.
      hard_mining (bool, optional): Whether to use hard mining. Defaults to
          False.
      reduction (str, optional): The method to reduce the loss.
          Options are "none", "mean" and "sum". Defaults to "mean".
      loss_weight (float, optional): The weight of loss. Defaults to 1.0.
class_docstr_tok: ["L2","loss","with","margin",".","Args",":","neg_pos_ub","(","int",",","optional",")",":","The","upper","bound","of","negative","to","positive","samples","in","hard","mining",".","Defaults","to","-1.","pos_margin","(","float",",","optional",")",":","The","similarity","margin","for","positive","samples","in","hard","mining",".","Defaults","to","-1.","neg_margin","(","float",",","optional",")",":","The","similarity","margin","for","negative","samples","in","hard","mining",".","Defaults","to","-1.","hard_mining","(","bool",",","optional",")",":","Whether","to","use","hard","mining",".","Defaults","to","False",".","reduction","(","str",",","optional",")",":","The","method","to","reduce","the","loss",".","Options","are","``","none","''",",","``","mean","''","and","``","sum","''",".","Defaults","to","``","mean","''",".","loss_weight","(","float",",","optional",")",":","The","weight","of","loss",".","Defaults","to","1.0","."]
docstr: Forward function.
  
  Args:
      pred (torch.Tensor): The prediction.
      target (torch.Tensor): The learning target of the prediction.
      weight (torch.Tensor, optional): The weight of loss for each
          prediction. Defaults to None.
      avg_factor (float, optional): Average factor that is used to
          average the loss. Defaults to None.
      reduction_override (str, optional): The reduction method used to
          override the original reduction method of the loss.
          Defaults to None.
docstr_tok: ["Forward","function",".","Args",":","pred","(","torch.Tensor",")",":","The","prediction",".","target","(","torch.Tensor",")",":","The","learning","target","of","the","prediction",".","weight","(","torch.Tensor",",","optional",")",":","The","weight","of","loss","for","each","prediction",".","Defaults","to","None",".","avg_factor","(","float",",","optional",")",":","Average","factor","that","is","used","to","average","the","loss",".","Defaults","to","None",".","reduction_override","(","str",",","optional",")",":","The","reduction","method","used","to","override","the","original","reduction","method","of","the","loss",".","Defaults","to","None","."]
code: def forward(
      self,
      pred: Tensor,
      target: Tensor,
      weight: Optional[Tensor] = None,
      avg_factor: Optional[float] = None,
      reduction_override: Optional[str] = None,
  ) -> Tensor:
      """Forward function.
  
      Args:
          pred (torch.Tensor): The prediction.
          target (torch.Tensor): The learning target of the prediction.
          weight (torch.Tensor, optional): The weight of loss for each
              prediction. Defaults to None.
          avg_factor (float, optional): Average factor that is used to
              average the loss. Defaults to None.
          reduction_override (str, optional): The reduction method used to
              override the original reduction method of the loss.
              Defaults to None.
      """
      assert reduction_override in (None, "none", "mean", "sum")
      reduction = (
          reduction_override if reduction_override else self.reduction
      )
      pred, weight, avg_factor = self.update_weight(
          pred, target, weight, avg_factor
      )
      loss_bbox = self.loss_weight * mse_loss(
          pred,
          target.float(),
          weight.float(),
          reduction=reduction,
          avg_factor=avg_factor,
      )
      return loss_bbox
  
file_path: mmdetection/mmdet/models/losses/margin_loss.py
imports: from typing import Optional, Tuple, Union
  import numpy
  import torch
  from mmengine.model import BaseModule
  from torch import Tensor
  from mmdet.registry import MODELS
  from .mse_loss import mse_loss
label_desc: Use image node_id 2 for calling the MarginL2Loss obj's underlying member method code with example usage: obj.forward(pred, target, weight, avg_factor, reduction_override) and returns: loss_bbox