class_docstr: Model using ResNet50 to predict single 3D oriented bounding box.
docstr: Computes the losses and adds them to the output dict.
  
  Args:
    inputs: Dict of inputs to the model.
    outputs: Dict of ouputs of the model.
    global_batch_size: The batch size over all replicas.
  
  Returns:
    The updated outputs.
docstr_tok: ["Computes","the","losses","and","adds","them","to","the","output","dict",".","Args",":","inputs",":","Dict","of","inputs","to","the","model",".","outputs",":","Dict","of","ouputs","of","the","model",".","global_batch_size",":","The","batch","size","over","all","replicas",".","Returns",":","The","updated","outputs","."]
code: def compute_loss(self, inputs, outputs, global_batch_size):
      """Computes the losses and adds them to the output dict.
  
      Args:
        inputs: Dict of inputs to the model.
        outputs: Dict of ouputs of the model.
        global_batch_size: The batch size over all replicas.
  
      Returns:
        The updated outputs.
      """
  
      # Compute partial losses
      size2d_loss = self.huber_loss(
          outputs["size2d"], inputs["box_dim2d"]
      )
      outputs["loss/size2d"] = size2d_loss
      center2d_loss = self.huber_loss(
          outputs["center2d"], inputs["center2d"]
      )
      outputs["loss/center2d"] = center2d_loss
  
      size3d_loss = self.huber_loss(
          outputs["size3d"], inputs["box_dim3d"]
      )
      outputs["loss/size3d"] = size3d_loss
      center3d_loss = self.huber_loss(
          outputs["center3d"], inputs["center3d"]
      )
      outputs["loss/center3d"] = center3d_loss
  
      outputs["error/center3d_x"] = tf.abs(
          outputs["center3d"][:, 0] - inputs["center3d"][:, 0]
      )
      outputs["error/center3d_y"] = tf.abs(
          outputs["center3d"][:, 1] - inputs["center3d"][:, 1]
      )
      outputs["error/center3d_z"] = tf.abs(
          outputs["center3d"][:, 2] - inputs["center3d"][:, 2]
      )
  
      local_batch_size = outputs["size3d"].shape[0]
      rad = inputs["rotation"] * -1 * math.pi / 180
      cos = tf.reshape(tf.cos(rad), [local_batch_size, 1, 1])
      sin = tf.reshape(tf.sin(rad), [local_batch_size, 1, 1])
      rotation = tf.concat(
          [
              tf.concat([cos, sin], axis=2),
              tf.concat([-sin, cos], axis=2),
          ],
          axis=1,
      )
      rotation_loss = tf.norm(
          outputs["rotation"] - rotation, ord="fro", axis=[-2, -1]
      )
      outputs["loss/rotation"] = rotation_loss
  
      # Compute mean over all losses based on global batch size
      for key in outputs.keys():
          if key.startswith("loss") or key.startswith("error"):
              outputs[key] = tf.nn.compute_average_loss(
                  outputs[key], global_batch_size=global_batch_size
              )
  
      # Total loss
      total_loss = (
          outputs["loss/center3d"]
          + outputs["loss/size3d"]
          + outputs["loss/rotation"]
      )
      outputs["loss/total"] = total_loss
      return outputs
  
imports: import math
  import tensorflow
label_desc: Use image node_id 2 for calling the SingleObjectModel obj's underlying member method code with example usage: obj.compute_loss(inputs, outputs, global_batch_size) and returns: outputs