code: def loss_boxes(
      *,
      src_boxes: jnp.ndarray,
      tgt_labels: jnp.ndarray,
      tgt_boxes: jnp.ndarray,
      indices: jnp.ndarray,
      bbox_loss_coef: float = 1.0,
      giou_loss_coef: float = 1.0,
      target_is_onehot: bool = False,
  ) -> ArrayDict:
      """Calculate DeformableDETR bounding box losses.
  
      Args:
        src_boxes: [bs, n_preds, 4].
        tgt_labels: [bs, n_max_targets].
        tgt_boxes: [bs, n_max_targets, 4].
        indices: [bs, 2, min(n_preds, n_max_targets)].
        bbox_loss_coef: L1 box coordinate loss coefficient.
        giou_loss_coef: Generalized IOU (GIOU) loss coefficient.
        target_is_onehot: Tgt is [bs, n_max_targets, n_classes]
  
      Returns:
        `loss_class`: Classification loss with coefficient applied.
      """
      src_indices = indices[..., 0, :]
      tgt_indices = indices[..., 1, :]
  
      src_boxes = model_utils.simple_gather(src_boxes, src_indices)
      tgt_boxes = model_utils.simple_gather(tgt_boxes, tgt_indices)
  
      # Some of the boxes are padding. We want to discount them from the loss.
      if target_is_onehot:
          tgt_not_padding = 1 - tgt_labels[..., 0]
      else:
          tgt_not_padding = tgt_labels != 0
      # Align this with the permuted target indices.
      tgt_not_padding = model_utils.simple_gather(
          tgt_not_padding, tgt_indices
      )
      tgt_not_padding = jnp.asarray(tgt_not_padding, dtype=jnp.float32)
  
      # To match official repo we do L1 loss on the cxcywh format.
      loss_bbox = model_utils.weighted_box_l1_loss(src_boxes, tgt_boxes)
      loss_bbox *= tgt_not_padding[..., None]
      loss_bbox = bbox_loss_coef * loss_bbox.sum()
  
      loss_giou = 1 - box_utils.generalized_box_iou(
          box_utils.box_cxcywh_to_xyxy(src_boxes),
          box_utils.box_cxcywh_to_xyxy(tgt_boxes),
          all_pairs=False,
          eps=1e-8,
      )
      loss_giou *= tgt_not_padding
      loss_giou = giou_loss_coef * loss_giou.sum()
  
      losses = {"loss_bbox": loss_bbox, "loss_giou": loss_giou}
      return losses
  
imports: import math
  from typing import Any, Dict, Optional, Sequence, Tuple, Union
  from absl import logging
  import flax.linen
  import jax
  import jax.numpy
  import ml_collections
  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
  from scenic.projects.baselines.deformable_detr.backbone import DeformableDETRBackbone
  from scenic.projects.baselines.deformable_detr.backbone import InputPosEmbeddingSine
  from scenic.projects.baselines.deformable_detr.backbone import mask_for_shape
  from scenic.projects.baselines.deformable_detr.deformable_transformer import BBoxCoordPredictor
  from scenic.projects.baselines.deformable_detr.deformable_transformer import DeformableDETRTransformer
  from scenic.projects.baselines.deformable_detr.deformable_transformer import inverse_sigmoid
  from scenic.projects.baselines.deformable_detr.deformable_transformer import pytorch_kernel_init
label_desc: Use image node_id 3 for calling a global function with example usage: loss_boxes() and returns: losses