import numpy as np def shape_iou(pred, gt): """ Calculates the intersection over union (IoU) of two point clouds. Args: pred: predicted point cloud gt: ground truth point cloud Returns: IoU value """ # conmpue the intersection intersection = np.logical_and(gt, pred) # compute the union union = np.logical_or(gt, pred) # compute the IoU iou_score = np.sum(intersection) / np.sum(union) return iou_score # show how to use it if __name__ == "__main__": # create two point clouds pred = np.array([[0, 0, 0], [1, 0, 1], [2, 2, 2]]) gt = np.array([[0, 0, 1], [1, 1, 1], [2, 3, 2]]) # calculate the IoU iou = shape_iou(pred, gt) # print the result print(iou)