class_docstr: LinkNet as described in `"LinkNet: Exploiting Encoder Representations for Efficient Semantic Segmentation"
  <https://arxiv.org/pdf/1707.03718.pdf>`_.
  
  Args:
  ----
      feature extractor: the backbone serving as feature extractor
      head_chans: number of channels in the head layers
      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 linknet loss, BCE with boosted box edges or focal loss. Focal loss implementation based on
  <https://github.com/tensorflow/addons/>`_.
  
  Args:
  ----
      out_map: output feature map of the model of shape (N, num_classes, 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","linknet","loss",",","BCE","with","boosted","box","edges","or","focal","loss",".","Focal","loss","implementation","based","on","<","https",":","\/\/github.com\/tensorflow\/addons\/",">","`","_",".","Args",":","--","--","out_map",":","output","feature","map","of","the","model","of","shape","(","N",",","num_classes",",","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,
      target: List[np.ndarray],
      gamma: float = 2.0,
      alpha: float = 0.5,
      eps: float = 1e-8,
  ) -> torch.Tensor:
      """Compute linknet loss, BCE with boosted box edges or focal loss. Focal loss implementation based on
      <https://github.com/tensorflow/addons/>`_.
  
      Args:
      ----
          out_map: output feature map of the model of shape (N, num_classes, 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
      """
      _target, _mask = self.build_target(target, out_map.shape[1:], False)  # type: ignore[arg-type]
  
      seg_target, seg_mask = torch.from_numpy(_target).to(
          dtype=out_map.dtype
      ), torch.from_numpy(_mask)
      seg_target, seg_mask = seg_target.to(out_map.device), seg_mask.to(
          out_map.device
      )
      seg_mask = seg_mask.to(dtype=torch.float32)
  
      bce_loss = F.binary_cross_entropy_with_logits(
          out_map, seg_target, reduction="none"
      )
      proba_map = torch.sigmoid(out_map)
  
      # Focal loss
      if gamma < 0:
          raise ValueError(
              "Value of gamma should be greater than or equal to zero."
          )
      p_t = proba_map * seg_target + (1 - proba_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(
          (0, 1, 2, 3)
      ) / seg_mask.sum((0, 1, 2, 3))
  
      # Dice loss
      inter = (seg_mask * proba_map * seg_target).sum((0, 1, 2, 3))
      cardinality = (seg_mask * (proba_map + seg_target)).sum(
          (0, 1, 2, 3)
      )
      dice_loss = 1 - 2 * (inter + eps) / (cardinality + eps)
  
      # Return the full loss (equal sum of focal loss and dice loss)
      return focal_loss + dice_loss
  
imports: from typing import Any, Callable, Dict, List, Optional, Tuple
  import numpy
  import torch
  from torch import nn
  from torch.nn import functional
  from torchvision.models._utils import IntermediateLayerGetter
  from doctr.file_utils import CLASS_NAME
  from doctr.models.classification import resnet18, resnet34, resnet50
  from ...utils import _bf16_to_float32, load_pretrained_params
  from .base import LinkNetPostProcessor, _LinkNet
label_desc: Use image node_id 3 for calling the LinkNet obj's underlying member method code with example usage: obj.compute_loss(out_map, target, gamma, alpha, eps) and returns: unknown