code: def single_image_loss(self, pre_loss, loss_label, neg_rto, n_min_neg):
      batch_size = pre_loss.shape[0]
  
      positive_loss, negative_loss = 0, 0
      for single_loss, single_label in zip(pre_loss, loss_label):
          # positive_loss
          pos_pixel = (single_label >= 0.1).float()
          n_pos_pixel = torch.sum(pos_pixel)
          pos_loss_region = single_loss * pos_pixel
          positive_loss += torch.sum(pos_loss_region) / max(
              n_pos_pixel, 1e-12
          )
  
          # negative_loss
          neg_pixel = (single_label < 0.1).float()
          n_neg_pixel = torch.sum(neg_pixel)
          neg_loss_region = single_loss * neg_pixel
  
          if n_pos_pixel != 0:
              if n_neg_pixel < neg_rto * n_pos_pixel:
                  negative_loss += (
                      torch.sum(neg_loss_region) / n_neg_pixel
                  )
              else:
                  n_hard_neg = max(n_min_neg, neg_rto * n_pos_pixel)
                  # n_hard_neg = neg_rto*n_pos_pixel
                  negative_loss += (
                      torch.sum(
                          torch.topk(
                              neg_loss_region.view(-1), int(n_hard_neg)
                          )[0]
                      )
                      / n_hard_neg
                  )
          else:
              # only negative pixel
              negative_loss += (
                  torch.sum(
                      torch.topk(neg_loss_region.view(-1), n_min_neg)[0]
                  )
                  / n_min_neg
              )
  
      total_loss = (positive_loss + negative_loss) / batch_size
  
      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_v3 obj's underlying member method code with example usage: obj.single_image_loss(pre_loss, loss_label, neg_rto, n_min_neg) and returns: total_loss