class_docstr: Base model for object detection or instance segmentation with matching.
  
  This model implements the classification and matching parts which are shared
  between the object detection and instance segmentation models.
docstr: Computes the unnormalized per-example classification loss and denom.
docstr_tok: ["Computes","the","unnormalized","per-example","classification","loss","and","denom","."]
code: def _compute_per_example_class_loss(
      self,
      *,
      tgt_labels_onehot: jnp.ndarray,
      src_log_p: jnp.ndarray,
      batch_weights: Optional[jnp.ndarray],
      neg_category_ids: Optional[jnp.ndarray] = None,
      loose_box: Optional[jnp.ndarray] = None,
  ) -> Tuple[jnp.ndarray, jnp.ndarray]:
      """Computes the unnormalized per-example classification loss and denom."""
      num_classes = src_log_p.shape[-1]
  
      # We want to weight the padded objects differently. So class 0 gets
      # eof_coef and others get 1.0.
      label_weights = jnp.concatenate(
          [
              jnp.array(
                  [self.config.get("eos_coef", 1.0)], dtype=jnp.float32
              ),
              jnp.ones(num_classes - 1),
          ]
      )
      unnormalized_loss_class = (
          model_utils.weighted_unnormalized_softmax_cross_entropy(
              src_log_p,
              tgt_labels_onehot,
              weights=batch_weights,
              label_weights=label_weights,
              logits_normalized=True,
          )
      )
  
      if label_weights is not None:
          denom = (tgt_labels_onehot * label_weights).sum(
              axis=[1, 2]
          )  # pytype: disable=wrong-arg-types  # jax-ndarray
      else:  # Normalize by number of boxes after removing padding label.
          denom = tgt_labels_onehot[..., 1:].sum(
              axis=[1, 2]
          )  # pytype: disable=wrong-arg-types  # jax-ndarray
  
      if batch_weights is not None:
          denom *= batch_weights
  
      return unnormalized_loss_class, denom
  
imports: import abc
  import functools
  from typing import Any, Callable, Dict, Optional, Tuple
  import jax
  import jax.numpy
  import ml_collections
  import numpy
  from scenic.model_lib import matchers
  from scenic.model_lib.base_models import base_model
  from scenic.model_lib.base_models import box_utils
  from scenic.model_lib.base_models import model_utils
label_desc: Use image node_id 7 for calling the BaseModelWithMatching obj's underlying member method code with example usage: obj._compute_per_example_class_loss() and returns: unnormalized_loss_class,  denom