class_docstr: Computes the confusion matrix for Intersection-Over-Union metrics.
  
  Formula:
  
  ```python
  iou = true_positives / (true_positives + false_positives + false_negatives)
  ```
  Intersection-Over-Union is a common evaluation metric for semantic image
  segmentation.
  
  From IoUs of individual classes, the MeanIoU can be computed as the mean of
  the individual IoUs.
  
  To compute IoUs, the predictions are accumulated in a confusion matrix,
  weighted by `sample_weight` and the metric is then calculated from it.
  
  If `sample_weight` is `None`, weights default to 1.
  Use `sample_weight` of 0 to mask values.
  
  Args:
      num_classes: The possible number of labels the prediction task can have.
      name: (Optional) string name of the metric instance.
      dtype: (Optional) data type of the metric result.
      ignore_class: Optional integer. The ID of a class to be ignored during
          metric computation. This is useful, for example, in segmentation
          problems featuring a "void" class (commonly -1 or 255) in
          segmentation maps. By default (`ignore_class=None`), all classes are
          considered.
      sparse_y_true: Whether labels are encoded using integers or
          dense floating point vectors. If `False`, the `argmax` function
          is used to determine each sample's most likely associated label.
      sparse_y_pred: Whether predictions are encoded using integers or
          dense floating point vectors. If `False`, the `argmax` function
          is used to determine each sample's most likely associated label.
      axis: (Optional) -1 is the dimension containing the logits.
          Defaults to `-1`.
class_docstr_tok: ["Computes","the","confusion","matrix","for","Intersection-Over-Union","metrics",".","Formula",":","``","`","python","iou","=","true_positives","\/","(","true_positives","+","false_positives","+","false_negatives",")","``","`","Intersection-Over-Union","is","a","common","evaluation","metric","for","semantic","image","segmentation",".","From","IoUs","of","individual","classes",",","the","MeanIoU","can","be","computed","as","the","mean","of","the","individual","IoUs",".","To","compute","IoUs",",","the","predictions","are","accumulated","in","a","confusion","matrix",",","weighted","by","`","sample_weight","`","and","the","metric","is","then","calculated","from","it",".","If","`","sample_weight","`","is","`","None","`",",","weights","default","to","1",".","Use","`","sample_weight","`","of","0","to","mask","values",".","Args",":","num_classes",":","The","possible","number","of","labels","the","prediction","task","can","have",".","name",":","(","Optional",")","string","name","of","the","metric","instance",".","dtype",":","(","Optional",")","data","type","of","the","metric","result",".","ignore_class",":","Optional","integer",".","The","ID","of","a","class","to","be","ignored","during","metric","computation",".","This","is","useful",",","for","example",",","in","segmentation","problems","featuring","a","``","void","''","class","(","commonly","-1","or","255",")","in","segmentation","maps",".","By","default","(","`","ignore_class=None","`",")",",","all","classes","are","considered",".","sparse_y_true",":","Whether","labels","are","encoded","using","integers","or","dense","floating","point","vectors",".","If","`","False","`",",","the","`","argmax","`","function","is","used","to","determine","each","sample","'s","most","likely","associated","label",".","sparse_y_pred",":","Whether","predictions","are","encoded","using","integers","or","dense","floating","point","vectors",".","If","`","False","`",",","the","`","argmax","`","function","is","used","to","determine","each","sample","'s","most","likely","associated","label",".","axis",":","(","Optional",")","-1","is","the","dimension","containing","the","logits",".","Defaults","to","`","-1","`","."]
docstr: Accumulates the confusion matrix statistics.
  
  Args:
      y_true: The ground truth values.
      y_pred: The predicted values.
      sample_weight: Optional weighting of each example. Can
          be a `Tensor` whose rank is either 0, or the same as `y_true`,
          and must be broadcastable to `y_true`. Defaults to `1`.
  
  Returns:
      Update op.
docstr_tok: ["Accumulates","the","confusion","matrix","statistics",".","Args",":","y_true",":","The","ground","truth","values",".","y_pred",":","The","predicted","values",".","sample_weight",":","Optional","weighting","of","each","example",".","Can","be","a","`","Tensor","`","whose","rank","is","either","0",",","or","the","same","as","`","y_true","`",",","and","must","be","broadcastable","to","`","y_true","`",".","Defaults","to","`","1","`",".","Returns",":","Update","op","."]
code: def update_state(self, y_true, y_pred, sample_weight=None):
      """Accumulates the confusion matrix statistics.
  
      Args:
          y_true: The ground truth values.
          y_pred: The predicted values.
          sample_weight: Optional weighting of each example. Can
              be a `Tensor` whose rank is either 0, or the same as `y_true`,
              and must be broadcastable to `y_true`. Defaults to `1`.
  
      Returns:
          Update op.
      """
  
      if not self.sparse_y_true:
          y_true = ops.argmax(y_true, axis=self.axis)
      if not self.sparse_y_pred:
          y_pred = ops.argmax(y_pred, axis=self.axis)
  
      y_true = ops.convert_to_tensor(y_true, dtype=self.dtype)
      y_pred = ops.convert_to_tensor(y_pred, dtype=self.dtype)
  
      # Flatten the input if its rank > 1.
      if len(y_pred.shape) > 1:
          y_pred = ops.reshape(y_pred, [-1])
  
      if len(y_true.shape) > 1:
          y_true = ops.reshape(y_true, [-1])
  
      if sample_weight is None:
          sample_weight = 1
  
      sample_weight = ops.convert_to_tensor(
          sample_weight, dtype=self.dtype
      )
  
      if len(sample_weight.shape) > 1:
          sample_weight = ops.reshape(sample_weight, [-1])
  
      sample_weight = ops.broadcast_to(sample_weight, ops.shape(y_true))
  
      if self.ignore_class is not None:
          ignore_class = ops.convert_to_tensor(
              self.ignore_class, y_true.dtype
          )
          valid_mask = ops.not_equal(y_true, ignore_class)
          y_true = y_true[valid_mask]
          y_pred = y_pred[valid_mask]
          if sample_weight is not None:
              sample_weight = sample_weight[valid_mask]
  
      y_pred = ops.cast(y_pred, dtype=self.dtype)
      y_true = ops.cast(y_true, dtype=self.dtype)
      sample_weight = ops.cast(sample_weight, dtype=self.dtype)
  
      current_cm = confusion_matrix(
          y_true,
          y_pred,
          self.num_classes,
          weights=sample_weight,
          dtype="float32",
      )
  
      return self.total_cm.assign(self.total_cm + current_cm)
  
imports: from keras import backend
  from keras import initializers
  from keras import ops
  from keras.api_export import keras_export
  from keras.metrics.metric import Metric
  from keras.metrics.metrics_utils import confusion_matrix
label_desc: Use image node_id 2 for calling the _IoUBase obj's underlying member method code with example usage: obj.update_state(y_true, y_pred, sample_weight) and returns: self