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: Train function.
docstr_tok: ["Train","function","."]
code: def train_sample(self, sample):
      """Train function."""
      with tf.GradientTape() as grad_tape:
          outputs = self.network(
              sample[self.sample_input_image], training=True
          )
          outputs[-1] = self.more_things(
              outputs[-1], sample, training=True
          )
          total_loss, per_output_per_head_loss = self.compute_loss(
              sample, sample, outputs
          )
      network_gradients = grad_tape.gradient(
          total_loss, self.network.trainable_variables
      )
      for i, grad in enumerate(network_gradients):
          if grad is not None:
              tf.debugging.check_numerics(
                  grad, "Invalid gradients: " + str(i)
              )
  
      gradients_norm = tf.constant(0)
      if self.clip_norm:
          network_gradients, gradients_norm = tf.clip_by_global_norm(
              network_gradients, clip_norm=self.clip_norm
          )
  
      self.optimizer.apply_gradients(
          zip(network_gradients, self.network.trainable_variables)
      )
  
      additional_logs = {
          "total_loss": total_loss,
          "gradients_norm": gradients_norm,
      }
  
      return {**additional_logs, **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 11 for calling the CenterNetVID obj's underlying member method code with example usage: obj.train_sample(sample) and returns: dict