class_docstr: Cross entropy loss for the task of semantic segmentation.
  
  Args:
      opts: command-line arguments
docstr: Computes the cross-entropy loss
  
  Args:
      pred_mask: Predicted segmentation mask
      target_mask: Target segmentation mask whose values are in the range `[0, C)`,
          where :math:`C` is the number of classes
      weight: class weights for handling class imbalancing.
  
  Shapes:
      pred_mask: Shape is [Batch size, Channels, Height, Width]
      target_mask: Shape is [Batch size, Height, Width]
      weight: Shape is [C]
  
  Returns:
      A scalar loss value
docstr_tok: ["Computes","the","cross-entropy","loss","Args",":","pred_mask",":","Predicted","segmentation","mask","target_mask",":","Target","segmentation","mask","whose","values","are","in","the","range","`","[","0",",","C",")","`",",","where",":","math",":","`","C","`","is","the","number","of","classes","weight",":","class","weights","for","handling","class","imbalancing",".","Shapes",":","pred_mask",":","Shape","is","[","Batch","size",",","Channels",",","Height",",","Width","]","target_mask",":","Shape","is","[","Batch","size",",","Height",",","Width","]","weight",":","Shape","is","[","C","]","Returns",":","A","scalar","loss","value"]
code: def _compute_loss(
      self,
      pred_mask: Tensor,
      target_mask: Tensor,
      weight: Optional[Tensor] = None,
  ) -> Tensor:
      """Computes the cross-entropy loss
  
      Args:
          pred_mask: Predicted segmentation mask
          target_mask: Target segmentation mask whose values are in the range `[0, C)`,
              where :math:`C` is the number of classes
          weight: class weights for handling class imbalancing.
  
      Shapes:
          pred_mask: Shape is [Batch size, Channels, Height, Width]
          target_mask: Shape is [Batch size, Height, Width]
          weight: Shape is [C]
  
      Returns:
          A scalar loss value
      """
  
      b, c, x_h, x_w = pred_mask.shape
      b, y_h, y_w = target_mask.shape
  
      # use label smoothing during training
      label_smoothing = self.label_smoothing if self.training else 0.0
  
      if x_h != y_h or x_w != y_w:
          # if predicting mask shape is not the same as target mask, resize it using
          # bilinear interpolation.
          pred_mask = F.interpolate(
              pred_mask,
              size=(y_h, y_w),
              mode="bilinear",
              align_corners=True,
          )
  
      loss = F.cross_entropy(
          input=pred_mask,
          target=target_mask,
          weight=weight,
          ignore_index=self.ignore_idx,
          label_smoothing=label_smoothing,
      )
  
      return loss
  
file_path: ml-cvnets/loss_fn/segmentation/cross_entropy.py
imports: import argparse
  from typing import Any, Mapping, Optional, Tuple, Union
  from torch import Tensor
  from torch.nn import functional
  from loss_fn import LOSS_REGISTRY
  from loss_fn.segmentation.base_segmentation_criteria import BaseSegmentationCriteria
  from loss_fn.utils.class_weighting import compute_class_weights
  from utils import logger
label_desc: Use image node_id 3 for calling the SegCrossEntropy obj's underlying member method code with example usage: obj._compute_loss(pred_mask, target_mask, weight) and returns: loss