code: def test_different_thresholds_weighted(self):
      y_true = [0, 1, 0, 1]
      y_pred = [0.1, 0.2, 0.4, 0.7]
  
      sample_weight = np.array([0.2, 0.3, 0.4, 0.1])
      # with threshold = 0.3, y_pred will be converted to [0, 0, 1, 1]
      # cm = [[0.2, 0.4],
      #       [0.3, 0.1]]
      # sum_row = [0.6, 0.4], sum_col = [0.5, 0.5], true_positives = [0.2,
      # 0.1]
      # iou = true_positives / (sum_row + sum_col - true_positives))
      expected_result = (
          0.2 / (0.6 + 0.5 - 0.2) + 0.1 / (0.4 + 0.5 - 0.1)
      ) / 2
      obj = metrics.BinaryIoU(target_class_ids=[0, 1], threshold=0.3)
      result = obj(y_true, y_pred, sample_weight=sample_weight)
      self.assertAllClose(result, expected_result, atol=1e-3)
  
      sample_weight = np.array([0.1, 0.2, 0.4, 0.3])
      # with threshold = 0.5, y_pred will be converted to [0, 0, 0, 1]
      # cm = [[0.1+0.4, 0],
      #       [0.2, 0.3]]
      # sum_row = [0.5, 0.5], sum_col = [0.7, 0.3], true_positives = [0.5,
      # 0.3]
      # iou = true_positives / (sum_row + sum_col - true_positives))
      expected_result = (
          0.5 / (0.5 + 0.7 - 0.5) + 0.3 / (0.5 + 0.3 - 0.3)
      ) / 2
      obj = metrics.BinaryIoU(target_class_ids=[0, 1], threshold=0.5)
      result = obj(y_true, y_pred, sample_weight=sample_weight)
      self.assertAllClose(result, expected_result, atol=1e-3)
  
imports: import numpy
  import pytest
  from keras import layers
  from keras import models
  from keras import testing
  from keras.metrics import iou_metrics
label_desc: Use image node_id 2 for calling the BinaryIoUTest obj's underlying member method code with example usage: obj.test_different_thresholds_weighted() without return types