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: OHEM sampling for a batch of imgs.
  
  Args:
      text_scores (Tensor): The text scores of size :math:`(H, W)`.
      gt_texts (Tensor): The gt text masks of size :math:`(H, W)`.
      gt_mask (Tensor): The gt effective mask of size :math:`(H, W)`.
  
  Returns:
      Tensor: The sampled mask of size :math:`(H, W)`.
docstr_tok: ["OHEM","sampling","for","a","batch","of","imgs",".","Args",":","text_scores","(","Tensor",")",":","The","text","scores","of","size",":","math",":","`","(","H",",","W",")","`",".","gt_texts","(","Tensor",")",":","The","gt","text","masks","of","size",":","math",":","`","(","H",",","W",")","`",".","gt_mask","(","Tensor",")",":","The","gt","effective","mask","of","size",":","math",":","`","(","H",",","W",")","`",".","Returns",":","Tensor",":","The","sampled","mask","of","size",":","math",":","`","(","H",",","W",")","`","."]
code: def _ohem_batch(
      self,
      text_scores: torch.Tensor,
      gt_texts: torch.Tensor,
      gt_mask: torch.Tensor,
  ) -> torch.Tensor:
      """OHEM sampling for a batch of imgs.
  
      Args:
          text_scores (Tensor): The text scores of size :math:`(H, W)`.
          gt_texts (Tensor): The gt text masks of size :math:`(H, W)`.
          gt_mask (Tensor): The gt effective mask of size :math:`(H, W)`.
  
      Returns:
          Tensor: The sampled mask of size :math:`(H, W)`.
      """
      assert isinstance(text_scores, torch.Tensor)
      assert isinstance(gt_texts, torch.Tensor)
      assert isinstance(gt_mask, torch.Tensor)
      assert len(text_scores.shape) == 3
      assert text_scores.shape == gt_texts.shape
      assert gt_texts.shape == gt_mask.shape
  
      sampled_masks = []
      for i in range(text_scores.shape[0]):
          sampled_masks.append(
              self._ohem_single(text_scores[i], gt_texts[i], gt_mask[i])
          )
  
      sampled_masks = torch.stack(sampled_masks)
  
      return sampled_masks
  
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 5 for calling the PANModuleLoss obj's underlying member method code with example usage: obj._ohem_batch(text_scores, gt_texts, gt_mask) and returns: sampled_masks