class_docstr: DBNet as described in `"Real-time Scene Text Detection with Differentiable Binarization"
  <https://arxiv.org/pdf/1911.08947.pdf>`_.
  
  Args:
  ----
      feature extractor: the backbone serving as feature extractor
      head_chans: the number of channels in the head
      deform_conv: whether to use deformable convolution
      assume_straight_pages: if True, fit straight bounding boxes only
      exportable: onnx exportable returns only logits
      cfg: the configuration dict of the model
      class_names: list of class names
class_docstr_tok: ["DBNet","as","described","in","`","``","Real-time","Scene","Text","Detection","with","Differentiable","Binarization","''","<","https",":","\/\/arxiv.org\/pdf\/1911.08947.pdf",">","`","_",".","Args",":","--","--","feature","extractor",":","the","backbone","serving","as","feature","extractor","head_chans",":","the","number","of","channels","in","the","head","deform_conv",":","whether","to","use","deformable","convolution","assume_straight_pages",":","if","True",",","fit","straight","bounding","boxes","only","exportable",":","onnx","exportable","returns","only","logits","cfg",":","the","configuration","dict","of","the","model","class_names",":","list","of","class","names"]
docstr: Compute a batch of gts, masks, thresh_gts, thresh_masks from a list of boxes
  and a list of masks for each image. From there it computes the loss with the model output
  
  Args:
  ----
      out_map: output feature map of the model of shape (N, C, H, W)
      thresh_map: threshold map of shape (N, C, H, W)
      target: list of dictionary where each dict has a `boxes` and a `flags` entry
      gamma: modulating factor in the focal loss formula
      alpha: balancing factor in the focal loss formula
      eps: epsilon factor in dice loss
  
  Returns:
  -------
      A loss tensor
docstr_tok: ["Compute","a","batch","of","gts",",","masks",",","thresh_gts",",","thresh_masks","from","a","list","of","boxes","and","a","list","of","masks","for","each","image",".","From","there","it","computes","the","loss","with","the","model","output","Args",":","--","--","out_map",":","output","feature","map","of","the","model","of","shape","(","N",",","C",",","H",",","W",")","thresh_map",":","threshold","map","of","shape","(","N",",","C",",","H",",","W",")","target",":","list","of","dictionary","where","each","dict","has","a","`","boxes","`","and","a","`","flags","`","entry","gamma",":","modulating","factor","in","the","focal","loss","formula","alpha",":","balancing","factor","in","the","focal","loss","formula","eps",":","epsilon","factor","in","dice","loss","Returns",":","--","--","--","-","A","loss","tensor"]
code: def compute_loss(
      self,
      out_map: torch.Tensor,
      thresh_map: torch.Tensor,
      target: List[np.ndarray],
      gamma: float = 2.0,
      alpha: float = 0.5,
      eps: float = 1e-8,
  ) -> torch.Tensor:
      """Compute a batch of gts, masks, thresh_gts, thresh_masks from a list of boxes
      and a list of masks for each image. From there it computes the loss with the model output
  
      Args:
      ----
          out_map: output feature map of the model of shape (N, C, H, W)
          thresh_map: threshold map of shape (N, C, H, W)
          target: list of dictionary where each dict has a `boxes` and a `flags` entry
          gamma: modulating factor in the focal loss formula
          alpha: balancing factor in the focal loss formula
          eps: epsilon factor in dice loss
  
      Returns:
      -------
          A loss tensor
      """
      if gamma < 0:
          raise ValueError(
              "Value of gamma should be greater than or equal to zero."
          )
  
      prob_map = torch.sigmoid(out_map)
      thresh_map = torch.sigmoid(thresh_map)
  
      targets = self.build_target(target, out_map.shape[1:], False)  # type: ignore[arg-type]
  
      seg_target, seg_mask = torch.from_numpy(
          targets[0]
      ), torch.from_numpy(targets[1])
      seg_target, seg_mask = seg_target.to(out_map.device), seg_mask.to(
          out_map.device
      )
      thresh_target, thresh_mask = torch.from_numpy(
          targets[2]
      ), torch.from_numpy(targets[3])
      thresh_target, thresh_mask = thresh_target.to(
          out_map.device
      ), thresh_mask.to(out_map.device)
  
      if torch.any(seg_mask):
          # Focal loss
          focal_scale = 10.0
          bce_loss = F.binary_cross_entropy_with_logits(
              out_map, seg_target, reduction="none"
          )
  
          p_t = prob_map * seg_target + (1 - prob_map) * (
              1 - seg_target
          )
          alpha_t = alpha * seg_target + (1 - alpha) * (1 - seg_target)
          # Unreduced version
          focal_loss = alpha_t * (1 - p_t) ** gamma * bce_loss
          # Class reduced
          focal_loss = (seg_mask * focal_loss).sum() / seg_mask.sum()
  
          # Compute dice loss for approx binary_map
          binary_map = 1 / (
              1 + torch.exp(-50.0 * (prob_map - thresh_map))
          )
          inter = (seg_mask * binary_map * seg_target).sum()  # type: ignore[attr-defined]
          cardinality = (seg_mask * (binary_map + seg_target)).sum()  # type: ignore[attr-defined]
          dice_loss = 1 - 2 * (inter + eps) / (cardinality + eps)
  
      # Compute l1 loss for thresh_map
      if torch.any(thresh_mask):
          l1_loss = (
              torch.abs(thresh_map - thresh_target) * thresh_mask
          ).sum() / (thresh_mask.sum() + eps)
  
      return l1_loss + focal_scale * focal_loss + dice_loss
  
imports: from typing import Any, Callable, Dict, List, Optional
  import numpy
  import torch
  from torch import nn
  from torch.nn import functional
  from torchvision.models import resnet34, resnet50
  from torchvision.models._utils import IntermediateLayerGetter
  from torchvision.ops.deform_conv import DeformConv2d
  from doctr.file_utils import CLASS_NAME
  from ...classification import mobilenet_v3_large
  from ...utils import _bf16_to_float32, load_pretrained_params
  from .base import DBPostProcessor, _DBNet
label_desc: Use image node_id 3 for calling the DBNet obj's underlying member method code with example usage: obj.compute_loss(out_map, thresh_map, target, gamma, alpha, eps) and returns: unknown