code: def test_bin_seg_3d(self):
      # define 3d examples
      target = torch.tensor(
          [
              # raw 0
              [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]],
              # raw 1
              [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]],
              # raw 2
              [[0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0]],
          ]
      )
  
      # add another dimension corresponding to the batch (batch size = 1 here)
      target = target.unsqueeze(0)  # shape (1, H, W, D)
      pred_very_good = (
          1000
          * F.one_hot(target, num_classes=2)
          .permute(0, 4, 1, 2, 3)
          .float()
      )
      pred_very_poor = (
          1000
          * F.one_hot(1 - target, num_classes=2)
          .permute(0, 4, 1, 2, 3)
          .float()
      )
  
      for w_mode in ["default", "GDL"]:
          # initialize the loss
          loss = GeneralizedWassersteinDiceLoss(
              dist_matrix=np.array([[0.0, 1.0], [1.0, 0.0]]),
              weighting_mode=w_mode,
          )
  
          # mean dice loss for pred_very_good should be close to 0
          loss_good = float(loss.forward(pred_very_good, target))
          self.assertAlmostEqual(loss_good, 0.0, places=3)
  
          # mean dice loss for pred_very_poor should be close to 1
          loss_poor = float(loss.forward(pred_very_poor, target))
          self.assertAlmostEqual(loss_poor, 1.0, places=3)
  
file_path: MONAI/tests/test_generalized_wasserstein_dice_loss.py
imports: from __future__ import annotations
  import unittest
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.optim
  from monai.losses import GeneralizedWassersteinDiceLoss
  from tests.utils import test_script_save
label_desc: Use image node_id 4 for calling the TestGeneralizedWassersteinDiceLoss obj's underlying member method code with example usage: obj.test_bin_seg_3d() without return types