code: def test_forward(self):
      # Shape mismatch between pred and gt
      with self.assertRaises(AssertionError):
          invalid_gt = torch.FloatTensor([0, 0, 0])
          self.bce_loss(self.pred, invalid_gt)
  
      # Shape mismatch between pred and mask
      with self.assertRaises(AssertionError):
          invalid_mask = torch.BoolTensor([True, False, False])
          self.bce_loss(self.pred, self.gt, invalid_mask)
  
      # Invalid pred or gt
      with self.assertRaises(AssertionError):
          invalid_gt = torch.FloatTensor([2, 3, 4, 5])
          self.bce_loss(self.pred, invalid_gt, self.mask)
      with self.assertRaises(AssertionError):
          invalid_pred = torch.FloatTensor([2, 3, 4, 5])
          self.bce_loss(invalid_pred, self.gt, self.mask)
  
      self.assertAlmostEqual(
          self.bce_loss(self.pred, self.gt).item(), 1.0567, delta=0.1
      )
      self.assertAlmostEqual(
          self.bce_loss(self.pred, self.gt, self.mask).item(),
          1.4067,
          delta=0.1,
      )
  
      # Test zero mask
      zero_mask = torch.FloatTensor([0, 0, 0, 0])
      self.assertAlmostEqual(
          self.bce_loss(self.pred, self.gt, zero_mask).item(), 0
      )
  
      # Test 0 < fallback_negative_num < negative numbers
      all_neg_gt = torch.zeros((4,))
      self.fallback_bce_loss = MaskedBalancedBCELoss(
          fallback_negative_num=1
      )
      self.assertAlmostEqual(
          self.fallback_bce_loss(
              self.pred, all_neg_gt, self.mask
          ).item(),
          0.51,
          delta=0.001,
      )
      # Test fallback_negative_num > negative numbers
      self.fallback_bce_loss = MaskedBalancedBCELoss(
          fallback_negative_num=3
      )
      self.assertAlmostEqual(
          self.fallback_bce_loss(
              self.pred, all_neg_gt, self.mask
          ).item(),
          0.308,
          delta=0.001,
      )
  
imports: from unittest import TestCase
  import torch
  from mmocr.models.common.losses import MaskedBalancedBCELoss, MaskedBalancedBCEWithLogitsLoss, MaskedBCELoss, MaskedBCEWithLogitsLoss
label_desc: Use image node_id 3 for calling the TestMaskedBalancedBCELoss obj's underlying member method code with example usage: obj.test_forward() without return types