class_docstr: The class for implementing PANet loss. This was partially adapted from
  https://github.com/whai362/pan_pp.pytorch and
  https://github.com/WenmuZhou/PAN.pytorch.
  
  PANet: `Efficient and Accurate Arbitrary-
  Shaped Text Detection with Pixel Aggregation Network
  <https://arxiv.org/abs/1908.05900>`_.
  
  Args:
      loss_text (dict) The loss config for text map. Defaults to
          dict(type='MaskedSquareDiceLoss').
      loss_kernel (dict) The loss config for kernel map. Defaults to
          dict(type='MaskedSquareDiceLoss').
      loss_embedding (dict) The loss config for embedding map. Defaults to
          dict(type='PANEmbLossV1').
      weight_text (float): The weight of text loss. Defaults to 1.
      weight_kernel (float): The weight of kernel loss. Defaults to 0.5.
      weight_embedding (float): The weight of embedding loss.
          Defaults to 0.25.
      ohem_ratio (float): The negative/positive ratio in ohem. Defaults to 3.
      shrink_ratio (tuple[float]) : The ratio of shrinking kernel. Defaults
          to (1.0, 0.5).
      max_shrink_dist (int or float): The maximum shrinking distance.
          Defaults to 20.
      reduction (str): The way to reduce the loss. Available options are
          "mean" and "sum". Defaults to 'mean'.
docstr: Compute PAN loss.
  
  Args:
      preds (dict): Raw predictions from model with
          shape :math:`(N, C, H, W)`.
      data_samples (list[TextDetDataSample]): The data samples.
  
  Returns:
      dict: The dict for pan losses with loss_text, loss_kernel,
      loss_aggregation and loss_discrimination.
docstr_tok: ["Compute","PAN","loss",".","Args",":","preds","(","dict",")",":","Raw","predictions","from","model","with","shape",":","math",":","`","(","N",",","C",",","H",",","W",")","`",".","data_samples","(","list","[","TextDetDataSample","]",")",":","The","data","samples",".","Returns",":","dict",":","The","dict","for","pan","losses","with","loss_text",",","loss_kernel",",","loss_aggregation","and","loss_discrimination","."]
code: def forward(
      self,
      preds: torch.Tensor,
      data_samples: Sequence[TextDetDataSample],
  ) -> Dict:
      """Compute PAN loss.
  
      Args:
          preds (dict): Raw predictions from model with
              shape :math:`(N, C, H, W)`.
          data_samples (list[TextDetDataSample]): The data samples.
  
      Returns:
          dict: The dict for pan losses with loss_text, loss_kernel,
          loss_aggregation and loss_discrimination.
      """
  
      gt_kernels, gt_masks = self.get_targets(data_samples)
      target_size = gt_kernels.size()[2:]
      preds = F.interpolate(preds, size=target_size, mode="bilinear")
      pred_texts = preds[:, 0, :, :]
      pred_kernels = preds[:, 1, :, :]
      inst_embed = preds[:, 2:, :, :]
      gt_kernels = gt_kernels.to(preds.device)
      gt_masks = gt_masks.to(preds.device)
  
      # compute embedding loss
      loss_emb = self.loss_embedding(
          inst_embed, gt_kernels[0], gt_kernels[1], gt_masks
      )
      gt_kernels[gt_kernels <= 0.5] = 0
      gt_kernels[gt_kernels > 0.5] = 1
      # compute text loss
      sampled_mask = self._ohem_batch(
          pred_texts.detach(), gt_kernels[0], gt_masks
      )
      pred_texts = torch.sigmoid(pred_texts)
      loss_texts = self.loss_text(
          pred_texts, gt_kernels[0], sampled_mask
      )
  
      # compute kernel loss
      pred_kernels = torch.sigmoid(pred_kernels)
      sampled_masks_kernel = (gt_kernels[0] > 0.5).float() * gt_masks
      loss_kernels = self.loss_kernel(
          pred_kernels, gt_kernels[1], sampled_masks_kernel
      )
  
      losses = [loss_texts, loss_kernels, loss_emb]
      if self.reduction == "mean":
          losses = [item.mean() for item in losses]
      else:
          losses = [item.sum() for item in losses]
  
      results = dict()
      results.update(
          loss_text=self.weight_text * losses[0],
          loss_kernel=self.weight_kernel * losses[1],
          loss_embedding=self.weight_embedding * losses[2],
      )
      return results
  
imports: import warnings
  from typing import Dict, Sequence, Tuple, Union
  import numpy
  import torch
  import torch.nn.functional
  from mmdet.models.utils import multi_apply
  from torch import nn
  from mmocr.registry import MODELS
  from mmocr.structures import TextDetDataSample
  from .seg_based_module_loss import SegBasedModuleLoss
label_desc: Use image node_id 2 for calling the PANModuleLoss obj's underlying member method code with example usage: obj.forward(preds, data_samples) and returns: results