class_docstr: An object detector model which can be trained using Model Maker's training API.
  
  Attributes:
    loss_trackers: List of tf.keras.metrics.Mean objects used to track the loss
      during training.
docstr: Overrides compute_loss from tf.keras.Model.
docstr_tok: ["Overrides","compute_loss","from","tf.keras.Model","."]
code: def compute_loss(
      self, x=None, y=None, y_pred=None, sample_weight=None
  ):
      """Overrides compute_loss from tf.keras.Model."""
      cls_loss_fn = focal_loss.FocalLoss(
          alpha=0.25, gamma=1.5, reduction=tf.keras.losses.Reduction.SUM
      )
      box_loss_fn = tf.keras.losses.Huber(
          0.1, reduction=tf.keras.losses.Reduction.SUM
      )
      labels = y
      outputs = y_pred
      # Sums all positives in a batch for normalization and avoids zero
      # num_positives_sum, which would lead to inf loss during training
      cls_sample_weight = labels["cls_weights"]
      box_sample_weight = labels["box_weights"]
      num_positives = tf.reduce_sum(box_sample_weight) + 1.0
      cls_sample_weight = cls_sample_weight / num_positives
      box_sample_weight = box_sample_weight / num_positives
      y_true_cls = loss_utils.multi_level_flatten(
          labels["cls_targets"], last_dim=None
      )
      y_true_cls = tf.one_hot(y_true_cls, self._num_classes)
      y_pred_cls = loss_utils.multi_level_flatten(
          outputs["cls_outputs"], last_dim=self._num_classes
      )
      y_true_box = loss_utils.multi_level_flatten(
          labels["box_targets"], last_dim=4
      )
      y_pred_box = loss_utils.multi_level_flatten(
          outputs["box_outputs"], last_dim=4
      )
  
      cls_loss = cls_loss_fn(
          y_true=y_true_cls,
          y_pred=y_pred_cls,
          sample_weight=cls_sample_weight,
      )
      box_loss = box_loss_fn(
          y_true=y_true_box,
          y_pred=y_pred_box,
          sample_weight=box_sample_weight,
      )
  
      model_loss = cls_loss + 50 * box_loss
      total_loss = model_loss
      regularization_losses = self._model.losses
      if regularization_losses:
          reg_loss = tf.reduce_sum(regularization_losses)
          total_loss = model_loss + reg_loss
      all_losses = {
          "total_loss": total_loss,
          "cls_loss": cls_loss,
          "box_loss": box_loss,
          "model_loss": model_loss,
      }
      for m in self.metrics:
          m.update_state(all_losses[m.name])
      return total_loss
  
imports: import os
  from typing import Mapping, Optional, Sequence, Union
  import tensorflow
  from mediapipe.model_maker.python.vision.object_detector import detection
  from mediapipe.model_maker.python.vision.object_detector import model_options
  from mediapipe.model_maker.python.vision.object_detector import model_spec
  from official.core import config_definitions
  from official.projects.qat.vision.configs import common
  from official.projects.qat.vision.modeling import factory
  from official.vision import configs
  from official.vision.losses import focal_loss
  from official.vision.losses import loss_utils
  from official.vision.modeling import factory
  from official.vision.modeling import retinanet_model
  from official.vision.modeling.layers import detection_generator
label_desc: Use image node_id 9 for calling the ObjectDetectorModel obj's underlying member method code with example usage: obj.compute_loss(x, y, y_pred, sample_weight) and returns: total_loss