class_docstr: Implements the cross entropy loss function.
  
  Args:
      weight (tuple|list|ndarray|Tensor, optional): A manual rescaling weight
          given to each class. Its length must be equal to the number of classes.
          Default ``None``.
      ignore_index (int64, optional): Specifies a target value that is ignored
          and does not contribute to the input gradient. Default ``255``.
      data_format (str, optional): The tensor format to use, 'NCHW' or 'NHWC'. Default ``'NCHW'``.
docstr: Forward computation.
  
  Args:
      logit (Tensor): Logit tensor, the data type is float32, float64. Shape is
          (N, C), where C is number of classes, and if shape is more than 2D, this
          is (N, C, D1, D2,..., Dk), k >= 1.
      label (Tensor): Label tensor, the data type is int64. Shape is (N), where each
          value is 0 <= label[i] <= C-1, and if shape is more than 2D, this is
          (N, D1, D2,..., Dk), k >= 1.
  Returns:
      (Tensor): The average loss.
docstr_tok: ["Forward","computation",".","Args",":","logit","(","Tensor",")",":","Logit","tensor",",","the","data","type","is","float32",",","float64",".","Shape","is","(","N",",","C",")",",","where","C","is","number","of","classes",",","and","if","shape","is","more","than","2D",",","this","is","(","N",",","C",",","D1",",","D2",",","...",",","Dk",")",",","k",">","=","1.","label","(","Tensor",")",":","Label","tensor",",","the","data","type","is","int64",".","Shape","is","(","N",")",",","where","each","value","is","0","<","=","label","[","i","]","<","=","C-1",",","and","if","shape","is","more","than","2D",",","this","is","(","N",",","D1",",","D2",",","...",",","Dk",")",",","k",">","=","1",".","Returns",":","(","Tensor",")",":","The","average","loss","."]
code: def forward(self, logit, label):
      """
      Forward computation.
  
      Args:
          logit (Tensor): Logit tensor, the data type is float32, float64. Shape is
              (N, C), where C is number of classes, and if shape is more than 2D, this
              is (N, C, D1, D2,..., Dk), k >= 1.
          label (Tensor): Label tensor, the data type is int64. Shape is (N), where each
              value is 0 <= label[i] <= C-1, and if shape is more than 2D, this is
              (N, D1, D2,..., Dk), k >= 1.
      Returns:
          (Tensor): The average loss.
      """
      label = label.astype("int64")
      # label.shape: │[3, 128, 128, 128] logit.shape: [3, 3, 128, 128, 128]
      channel_axis = self.data_format.index(
          "C"
      )  # NCDHW -> 1, NDHWC -> 4
  
      if len(logit.shape) == 4:
          logit = logit.unsqueeze(0)
  
      if self.weight is None:
          self.weight = class_weights(logit)
  
      if self.weight is not None and logit.shape[channel_axis] != len(
          self.weight
      ):
          raise ValueError(
              "The number of weights = {} must be the same as the number of classes = {}.".format(
                  len(self.weight), logit.shape[channel_axis]
              )
          )
  
      if channel_axis == 1:
          logit = paddle.transpose(
              logit, [0, 2, 3, 4, 1]
          )  # NCDHW -> NDHWC
  
      loss = F.cross_entropy(
          logit + self.EPS,
          label,
          reduction="mean",
          ignore_index=self.ignore_index,
          weight=self.weight,
      )
  
      return loss
  
file_path: PaddleSeg/contrib/MedicalSeg/medicalseg/models/losses/cross_entropy_loss.py
imports: import paddle
  from paddle import nn
  import paddle.nn.functional
  from medicalseg.models.losses import class_weights
  from medicalseg.cvlibs import manager
label_desc: Use image node_id 2 for calling the CrossEntropyLoss obj's underlying member method code with example usage: obj.forward(logit, label) and returns: loss