'Reshape instance segmentation masks.
The instance segmentation masks are reshaped to [num_instances, height,
width] and cast to boolean type to save memory.
Args:
keys_to_tensors: a dictionary from keys to tensors.
Returns:
A 3-D boolean tensor of shape [num_instances, height, width].'

def _reshape_instance_masks(self, keys_to_tensors):

    masks = keys_to_tensors['image/segmentation/object']
    if isinstance(masks, tf.SparseTensor):
        masks = tf.sparse_tensor_to_dense(masks)
    height = keys_to_tensors['image/height']
    width = keys_to_tensors['image/width']
    to_shape = tf.cast(tf.stack([(-1), height, width]), tf.int32)
    return tf.cast(tf.reshape(masks, to_shape), tf.bool)
