class_docstr: Constructs the instance mask for each object in the original image.
docstr: Constructs the instance mask for each object in the original image.
  
  Args:
    features: dict; Contains a single unbatched input example with keys
      `inputs` and `label`. `label` contains the key `masks`, which is a COCO
      panoptic image (with object IDs encoded in RGB).
  
  Returns:
    An updated feature dict with a mask tensor of shape [num_objects, H, W].
code: def __call__(self, features):
      """Constructs the instance mask for each object in the original image.
  
      Args:
        features: dict; Contains a single unbatched input example with keys
          `inputs` and `label`. `label` contains the key `masks`, which is a COCO
          panoptic image (with object IDs encoded in RGB).
  
      Returns:
        An updated feature dict with a mask tensor of shape [num_objects, H, W].
      """
  
      if "masks" not in features["label"]:
          raise ValueError(
              "masks are required when using this transformation."
          )
  
      panoptic_image = features["label"]["masks"]
      object_ids = features["label"]["objects/id"]
  
      # Number of objects in the image.
      num_objects = tf.shape(object_ids)[0]
      object_ids_map = tf.reshape(object_ids, (num_objects, 1, 1))
      object_ids_map = tf.cast(object_ids_map, dtype=tf.int32)
  
      # Reconstruct object ids from the panoptic image per-pixel segment id.
      panoptic_image = tf.cast(panoptic_image, dtype=tf.int32)
      # convert RGB from panoptic_image to object id
      object_id_mask = (
          panoptic_image[:, :, 0]
          + panoptic_image[:, :, 1] * 256
          + panoptic_image[:, :, 2] * 256 * 256
      )
  
      # `instance_masks` contains values in {0,1} to indicate presence of this
      # object for each pixel. instance_masks.shape = [num_objects, height, width]
      instance_masks = tf_int32(
          tf.equal(object_id_mask, object_ids_map)
      )
  
      # Add channel dimension. This makes things like hflip easier because it will
      # treat the leading dimension (num_objects) as batch dimension:
      instance_masks = instance_masks[..., tf.newaxis]
  
      features["label"]["masks"] = tf.identity(instance_masks, "masks")
  
      return features
  
imports: from typing import Any, Dict
  import tensorflow
label_desc: Use image node_id 1 for calling the GetCocoInstanceMasks obj's underlying member method code with example usage: obj.__call__(features) and returns: features