docstr: For gamma=0 the focal loss reduces to the cross entropy loss
docstr_tok: ["For","gamma=0","the","focal","loss","reduces","to","the","cross","entropy","loss"]
code: def test_consistency_with_cross_entropy_2d_no_reduction(self):
      """For gamma=0 the focal loss reduces to the cross entropy loss"""
  
      focal_loss = FocalLoss(
          to_onehot_y=False, gamma=0.0, reduction="none", weight=1.0
      )
      ce = nn.BCEWithLogitsLoss(reduction="none")
      max_error = 0
      class_num = 10
      batch_size = 128
      for _ in range(100):
          # Create a random tensor of shape (batch_size, class_num, 8, 4)
          x = torch.rand(
              batch_size, class_num, 8, 4, requires_grad=True
          )
          # Create a random batch of classes
          l = torch.randint(
              low=0, high=2, size=(batch_size, class_num, 8, 4)
          ).float()
          if torch.cuda.is_available():
              x = x.cuda()
              l = l.cuda()
          output0 = focal_loss(x, l)
          output1 = ce(x, l)
          a = output0.cpu().detach().numpy()
          b = output1.cpu().detach().numpy()
          error = np.abs(a - b)
          max_error = np.maximum(error, max_error)
  
      assert np.allclose(max_error, 0)
  
imports: from __future__ import annotations
  import unittest
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  from parameterized import parameterized
  from monai.losses import FocalLoss
  from monai.networks import one_hot
  from tests.utils import test_script_save
label_desc: Use image node_id 3 for calling the TestFocalLoss obj's underlying member method code with example usage: obj.test_consistency_with_cross_entropy_2d_no_reduction() without return types