code: def criterion(
      inputs,
      target,
      loss_weight=None,
      num_classes: int = 2,
      dice: bool = True,
      ignore_index: int = -100,
  ):
      losses = {}
      for name, x in inputs.items():
          # 忽略target中值为255的像素，255的像素是目标边缘或者padding填充
          loss = nn.functional.cross_entropy(
              x, target, ignore_index=ignore_index, weight=loss_weight
          )
          if dice is True:
              dice_target = build_target(
                  target, num_classes, ignore_index
              )
              loss += dice_loss(
                  x,
                  dice_target,
                  multiclass=True,
                  ignore_index=ignore_index,
              )
          losses[name] = loss
  
      if len(losses) == 1:
          return losses["out"]
  
      return losses["out"] + 0.5 * losses["aux"]
  
file_path: deep-learning-for-image-processing/pytorch_segmentation/unet/train_utils/train_and_eval.py
imports: import torch
  from torch import nn
  import train_utils.distributed_utils
  from .dice_coefficient_loss import dice_loss, build_target
label_desc: Use image node_id 1 for calling a global function with example usage: criterion(inputs, target, loss_weight, num_classes, dice, ignore_index) and returns: unknown, losses