class_docstr: CenterNet network using Hourglass from https://arxiv.org/abs/1904.07850S.
class_docstr_tok: ["CenterNet","network","using","Hourglass","from","https",":","\/\/arxiv.org\/abs\/1904.07850S","."]
docstr: Loss helper.
docstr_tok: ["Loss","helper","."]
code: def _compute_loss(outputs, sample, losses, num_samples):
      """Loss helper."""
      per_output_per_head_loss = {}
      total_loss = 0
      for ii, output in enumerate([outputs[-1]]):
          for head_name in losses:
              head_output = output[head_name]
              head_loss = losses[head_name]["loss"]
              if head_name in sample:
                  head_gt = sample[head_name]
              else:
                  head_gt = None
              head_weight = losses[head_name]["weight"]
              current_loss = head_loss(head_output, head_gt, sample)
              info = f"Loss {head_name}:{current_loss}"
              logging.info(info)
              if not isinstance(current_loss, tf.Tensor):
                  logging.info(current_loss.numpy())
              current_loss = tf.reduce_sum(current_loss) / tf.cast(
                  num_samples, current_loss.dtype
              )
              per_output_per_head_loss[
                  f"{head_name}_{ii}"
              ] = current_loss
              total_loss = total_loss + current_loss * head_weight
  
      total_loss = total_loss / len(outputs)
      return total_loss, per_output_per_head_loss
  
imports: import collections
  import os
  import random
  import string
  import time
  from absl import logging
  import numpy
  import tensorflow
  from tensorflow_graphics.projects.points_to_3Dobjects.models import centernet_utils
  from tensorflow_graphics.projects.points_to_3Dobjects.networks import hourglass
  from tensorflow_graphics.projects.points_to_3Dobjects.transforms import transforms
  from tensorflow_graphics.projects.points_to_3Dobjects.utils import image
  from google3.pyglib import gfile
label_desc: Use image node_id 5 for calling the CenterNetVID obj's underlying member method code with example usage: obj._compute_loss(outputs, sample, losses, num_samples) and returns: total_loss,  per_output_per_head_loss