code: def test_dice_loss_binary():
      eps = 1e-5
      criterion = L.DiceLoss(mode="binary", from_logits=False)
  
      # Ideal case
      y_pred = torch.tensor([1.0, 1.0, 1.0]).view(1, 1, 1, -1)
      y_true = torch.tensor(([1, 1, 1])).view(1, 1, 1, -1)
      loss = criterion(y_pred, y_true)
      assert float(loss) == pytest.approx(0.0, abs=eps)
  
      y_pred = torch.tensor([1.0, 0.0, 1.0]).view(1, 1, 1, -1)
      y_true = torch.tensor(([1, 0, 1])).view(1, 1, 1, -1)
      loss = criterion(y_pred, y_true)
      assert float(loss) == pytest.approx(0.0, abs=eps)
  
      y_pred = torch.tensor([0.0, 0.0, 0.0]).view(1, 1, 1, -1)
      y_true = torch.tensor(([0, 0, 0])).view(1, 1, 1, -1)
      loss = criterion(y_pred, y_true)
      assert float(loss) == pytest.approx(0.0, abs=eps)
  
      # Worst case
      y_pred = torch.tensor([1.0, 1.0, 1.0]).view(1, 1, -1)
      y_true = torch.tensor([0, 0, 0]).view(1, 1, 1, -1)
      loss = criterion(y_pred, y_true)
      assert float(loss) == pytest.approx(0.0, abs=eps)
  
      y_pred = torch.tensor([1.0, 0.0, 1.0]).view(1, 1, -1)
      y_true = torch.tensor([0, 1, 0]).view(1, 1, 1, -1)
      loss = criterion(y_pred, y_true)
      assert float(loss) == pytest.approx(1.0, abs=eps)
  
      y_pred = torch.tensor([0.0, 0.0, 0.0]).view(1, 1, -1)
      y_true = torch.tensor([1, 1, 1]).view(1, 1, 1, -1)
      loss = criterion(y_pred, y_true)
      assert float(loss) == pytest.approx(1.0, abs=eps)
  
imports: import numpy
  import pytest
  import pytorch_toolbelt.losses.functional
  import torch
  from pytorch_toolbelt import losses
  from torch import nn
  from pytorch_toolbelt.losses import BinaryFocalLoss, CrossEntropyFocalLoss
label_desc: Use image node_id 6 for calling a global function with example usage: test_dice_loss_binary() without return types