code: def batch_image_loss(
      self, pred_score, label_score, neg_rto, n_min_neg
  ):
      # positive_loss
      positive_pixel = (label_score > 0.1).float()
      positive_pixel_number = torch.sum(positive_pixel)
  
      positive_loss_region = pred_score * positive_pixel
  
      # negative_loss
      negative_pixel = (label_score <= 0.1).float()
      negative_pixel_number = torch.sum(negative_pixel)
      negative_loss_region = pred_score * negative_pixel
  
      if positive_pixel_number != 0:
          if negative_pixel_number < neg_rto * positive_pixel_number:
              negative_loss = (
                  torch.sum(
                      torch.topk(
                          negative_loss_region.view(-1),
                          n_min_neg,
                          sorted=False,
                      )[0]
                  )
                  / n_min_neg
              )
          else:
              negative_loss = torch.sum(
                  torch.topk(
                      negative_loss_region.view(-1),
                      int(neg_rto * positive_pixel_number),
                      sorted=False,
                  )[0]
              ) / (positive_pixel_number * neg_rto)
          positive_loss = (
              torch.sum(positive_loss_region) / positive_pixel_number
          )
      else:
          # only negative pixel
          negative_loss = (
              torch.sum(
                  torch.topk(
                      negative_loss_region.view(-1),
                      n_min_neg,
                      sorted=False,
                  )[0]
              )
              / n_min_neg
          )
          positive_loss = 0.0
      total_loss = positive_loss + negative_loss
      return total_loss
  
file_path: EasyOCR/trainer/craft/loss/mseloss.py
imports: import torch
  import torch.nn
label_desc: Use image node_id 2 for calling the Maploss_v2 obj's underlying member method code with example usage: obj.batch_image_loss(pred_score, label_score, neg_rto, n_min_neg) and returns: total_loss