docstr: Args:
      pred: (N, 1, H, W).
      gt: (N, H, W).
      mask: (N, H, W).
docstr_tok: ["Args",":","pred",":","(","N",",","1",",","H",",","W",")",".","gt",":","(","N",",","H",",","W",")",".","mask",":","(","N",",","H",",","W",")","."]
code: def forward(self, pred: torch.Tensor, gt, mask):
      """
      Args:
          pred: (N, 1, H, W).
          gt: (N, H, W).
          mask: (N, H, W).
      """
      loss = torch.abs(pred[:, 0] - gt)
      positive = loss * mask
      negative = loss * (1 - mask)
      positive_count = int(mask.sum())
      negative_count = min(
          int((1 - mask).sum()),
          int(positive_count * self.negative_ratio),
      )
      negative_loss, _ = torch.topk(negative.view(-1), negative_count)
      negative_loss = negative_loss.sum() / negative_count
      positive_loss = positive.sum() / positive_count
      return positive_loss + negative_loss, dict(
          l1_loss=positive_loss, nge_l1_loss=negative_loss
      )
  
file_path: EasyOCR/easyocr/DBNet/decoders/l1_loss.py
imports: import torch
  import torch.nn
label_desc: Use image node_id 2 for calling the BalanceL1Loss obj's underlying member method code with example usage: obj.forward(pred, gt, mask) and returns: unknown,  dict