code: def instance_iou_loss(
      predicted_clusters: List[torch.Tensor],
      cluster_scores: torch.Tensor,
      instance_labels: torch.Tensor,
      batch: torch.Tensor,
      min_iou_threshold=0.25,
      max_iou_threshold=0.75,
  ):
      """Loss that promotes higher scores for clusters with higher instance iou,
      see https://arxiv.org/pdf/2004.01658.pdf equation (7)
      """
      assert len(predicted_clusters) == cluster_scores.shape[0]
      ious = instance_iou(
          predicted_clusters, instance_labels, batch
      ).max(1)[0]
      lower_mask = ious < min_iou_threshold
      higher_mask = ious > max_iou_threshold
      middle_mask = torch.logical_and(
          torch.logical_not(lower_mask), torch.logical_not(higher_mask)
      )
      assert (
          torch.sum(lower_mask + higher_mask + middle_mask)
          == ious.shape[0]
      )
      shat = torch.zeros_like(ious)
      iou_middle = ious[middle_mask]
      shat[higher_mask] = 1
      shat[middle_mask] = (iou_middle - min_iou_threshold) / (
          max_iou_threshold - min_iou_threshold
      )
      return torch.nn.functional.binary_cross_entropy(
          cluster_scores, shat
      )
  
imports: import torch
  from typing import List
  from torch_points_kernels import instance_iou
label_desc: Use image node_id 2 for calling a global function with example usage: instance_iou_loss(predicted_clusters, cluster_scores, instance_labels, batch, min_iou_threshold, max_iou_threshold) and returns: torch