code: def test_weighted(self):
      y_true = np.array(
          [
              [0, 0, 1],
              [1, 0, 0],
              [0, 1, 0],
              [1, 0, 0],
              [1, 0, 0],
          ]
      )
      # y_true will be converted to [2, 0, 1, 0, 0]
      y_pred = np.array(
          [
              [0.2, 0.3, 0.5],
              [0.1, 0.2, 0.7],
              [0.5, 0.3, 0.1],
              [0.1, 0.4, 0.5],
              [0.6, 0.2, 0.2],
          ]
      )
      # y_pred will be converted to [2, 2, 0, 2, 0]
      sample_weight = [0.1, 0.2, 0.3, 0.3, 0.1]
      # cm = [[0.1, 0, 0.2+0.3],
      #       [0.3, 0, 0],
      #       [0, 0, 0.1]]
      # sum_row = [0.4, 0, 0.6], sum_col = [0.6, 0.3, 0.1]
      # true_positives = [0.1, 0, 0.1]
      # iou = true_positives / (sum_row + sum_col - true_positives))
      expected_result = (
          0.1 / (0.4 + 0.6 - 0.1) + 0 + 0.1 / (0.6 + 0.1 - 0.1)
      ) / 3
      obj = metrics.OneHotMeanIoU(num_classes=3)
      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 OneHotMeanIoUTest obj's underlying member method code with example usage: obj.test_weighted() without return types