class_docstr: Compute the generalized Wasserstein Dice Loss defined in:
  
      Fidon L. et al. (2017) Generalised Wasserstein Dice Score for Imbalanced Multi-class
      Segmentation using Holistic Convolutional Networks. BrainLes 2017.
  
  Or its variant (use the option weighting_mode="GDL") defined in the Appendix of:
  
      Tilborghs, S. et al. (2020) Comparative study of deep learning methods for the automatic
      segmentation of lung, lesion and lesion type in CT scans of COVID-19 patients.
      arXiv preprint arXiv:2007.15546
  
  Adapted from:
      https://github.com/LucasFidon/GeneralizedWassersteinDiceLoss
class_docstr_tok: ["Compute","the","generalized","Wasserstein","Dice","Loss","defined","in",":","Fidon","L.","et","al",".","(","2017",")","Generalised","Wasserstein","Dice","Score","for","Imbalanced","Multi-class","Segmentation","using","Holistic","Convolutional","Networks",".","BrainLes","2017",".","Or","its","variant","(","use","the","option","weighting_mode=","''","GDL","''",")","defined","in","the","Appendix","of",":","Tilborghs",",","S.","et","al",".","(","2020",")","Comparative","study","of","deep","learning","methods","for","the","automatic","segmentation","of","lung",",","lesion","and","lesion","type","in","CT","scans","of","COVID-19","patients",".","arXiv","preprint","arXiv:2007.15546","Adapted","from",":","https",":","\/\/github.com\/LucasFidon\/GeneralizedWassersteinDiceLoss"]
docstr: Args:
      flat_target: the target tensor.
docstr_tok: ["Args",":","flat_target",":","the","target","tensor","."]
code: def _compute_alpha_generalized_true_positives(
      self, flat_target: torch.Tensor
  ) -> torch.Tensor:
      """
      Args:
          flat_target: the target tensor.
      """
      alpha: torch.Tensor = (
          torch.ones((flat_target.size(0), self.num_classes))
          .float()
          .to(flat_target.device)
      )
      if self.alpha_mode == "GDL":  # GDL style
          # Define alpha like in the generalized dice loss
          # i.e. the inverse of the volume of each class.
          one_hot_f = (
              F.one_hot(flat_target, num_classes=self.num_classes)
              .permute(0, 2, 1)
              .float()
          )
          volumes = torch.sum(one_hot_f, dim=2)
          alpha = 1.0 / (volumes + 1.0)
      else:  # default, i.e. like in the original paper
          # alpha weights are 0 for the background and 1 the other classes
          alpha[:, 0] = 0.0
      return alpha
  
imports: from __future__ import annotations
  import warnings
  from collections.abc import Callable, Sequence
  from typing import Any
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from torch.nn.modules.loss import _Loss
  from monai.losses.focal_loss import FocalLoss
  from monai.losses.spatial_mask import MaskedLoss
  from monai.networks import one_hot
  from monai.utils import DiceCEReduction, LossReduction, Weight, deprecated_arg, look_up_option, pytorch_after
label_desc: Use image node_id 6 for calling the GeneralizedWassersteinDiceLoss obj's underlying member method code with example usage: obj._compute_alpha_generalized_true_positives(flat_target) and returns: alpha