class_docstr: Shape auto-encoder with multiple convex polytopes.
  
  Attributes:
    n_params: int, the number of hyperplane parameters.
class_docstr_tok: ["Shape","auto-encoder","with","multiple","convex","polytopes",".","Attributes",":","n_params",":","int",",","the","number","of","hyperplane","parameters","."]
docstr: Compute loss given a batch of data.
  
  Args:
    batch: Dict, must contains:
      "image": [batch_size, image_h, image_w, image_d],
      "depth": [batch_size, depth_h, depth_w, depth_d],
      "point": [batch_size, n_points, dims],
      "point_label": [batch_size, n_points, 1],
    training: bool, use training mode if true.
    optimizer: tf.train.Optimizer, optimizer used for training.
  
  Returns:
    train_loss: tf.Operation, loss hook.
    train_op: tf.Operation, optimization op.
    global_step: tf.Operation, gloabl step hook.
docstr_tok: ["Compute","loss","given","a","batch","of","data",".","Args",":","batch",":","Dict",",","must","contains",":","``","image","''",":","[","batch_size",",","image_h",",","image_w",",","image_d","]",",","``","depth","''",":","[","batch_size",",","depth_h",",","depth_w",",","depth_d","]",",","``","point","''",":","[","batch_size",",","n_points",",","dims","]",",","``","point_label","''",":","[","batch_size",",","n_points",",","1","]",",","training",":","bool",",","use","training","mode","if","true",".","optimizer",":","tf.train.Optimizer",",","optimizer","used","for","training",".","Returns",":","train_loss",":","tf.Operation",",","loss","hook",".","train_op",":","tf.Operation",",","optimization","op",".","global_step",":","tf.Operation",",","gloabl","step","hook","."]
code: def compute_loss(self, batch, training, optimizer=None):
      """Compute loss given a batch of data.
  
      Args:
        batch: Dict, must contains:
          "image": [batch_size, image_h, image_w, image_d],
          "depth": [batch_size, depth_h, depth_w, depth_d],
          "point": [batch_size, n_points, dims],
          "point_label": [batch_size, n_points, 1],
        training: bool, use training mode if true.
        optimizer: tf.train.Optimizer, optimizer used for training.
  
      Returns:
        train_loss: tf.Operation, loss hook.
        train_op: tf.Operation, optimization op.
        global_step: tf.Operation, gloabl step hook.
      """
      img = batch["image"]
      depth = batch["depth"]
      points = batch["point"]
      gt = batch["point_label"]
  
      if self._image_input:
          beta = self.encode(img, training=training)
      else:
          beta = self.encode(depth, training=training)
      output, (trans, imgsum, offset, image_indica) = self.decode(
          beta, points, training=training
      )
  
      sample_loss = self._compute_sample_loss(gt, output)
  
      overlap_loss = self._compute_overlap_loss(imgsum)
  
      bbx_loss = self._compute_bbx_loss(trans, points, gt)
  
      center_loss = tf.reduce_mean(tf.square(offset))
  
      balance_loss = self._compute_balance_loss(image_indica, gt)
  
      loss = (
          overlap_loss * self._w_overlap
          + balance_loss * self._w_balance
          + center_loss * self._w_center
          + bbx_loss
          + sample_loss
      )
  
      if training:
          tf.summary.scalar("sample_loss", sample_loss)
          tf.summary.scalar("overlap_loss", overlap_loss)
          tf.summary.scalar("bbx_loss", bbx_loss)
          tf.summary.scalar("center_loss", center_loss)
          tf.summary.scalar("balance_loss", balance_loss)
          tf.summary.scalar("train_loss", loss)
          tf.summary.image("input_images", img)
  
      if training:
          global_step = tf.train.get_or_create_global_step()
          update_ops = self.updates
          with tf.control_dependencies(update_ops):
              gradients, variables = zip(
                  *optimizer.compute_gradients(loss)
              )
              gradients, unused_var = tf.clip_by_global_norm(
                  gradients, 5.0
              )
              train_op = optimizer.apply_gradients(
                  zip(gradients, variables), global_step=global_step
              )
          return loss, train_op, global_step
      else:
          occ = tf.cast(output >= self._level_set, tf.float32)
          intersection = tf.reduce_sum(occ * gt, axis=(1, 2))
          union = tf.reduce_sum(tf.maximum(occ, gt), axis=(1, 2))
          iou = intersection / union
          return loss, iou
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import numpy
  import tensorflow.compat.v1
  from tensorflow_graphics.projects.cvxnet.lib import resnet
label_desc: Use image node_id 2 for calling the MultiConvexNet obj's underlying member method code with example usage: obj.compute_loss(batch, training, optimizer) and returns: loss,  train_op,  global_step, loss,  iou