def naive_compute_iou_matrix(sorted_detections, ground_truths): """Computes the iou scores between all pairs of geometries in a naive fashion. Args: sorted_detections (ndarray, list) : A ndarray of detections stored as: * Bounding boxes for a given class where each row is a detection stored as: ``[BoundingBox, confidence]`` * Polygons for a given class where each row is a detection stored as: ``[Polygon, confidence]`` * Points for a given class where each row is a detection stored as: ``[Point, confidence]`` ground_truths (ndarray,list) : A ndarray of ground truth stored as: * Bounding boxes for a given class where each row is a ground truth stored as: ``[BoundingBox]`` * Polygons for a given class where each row is a ground truth stored as: ``[Polygon]`` * Points for a given class where each row is a ground truth stored as: ``[Point]`` Returns: ndarray : An IoU matrix (#detections, #ground truth) """ # We prepare the IoU matrix (#detection, #gt) iou = np.zeros((sorted_detections.shape[0], len(ground_truths))) # Naive iterative IoU matrix construction (Note: we iterate over the sorted detections) for k, ground_truth in enumerate(ground_truths): for m, detection in enumerate(sorted_detections): iou[m, k] = area(intersection(detection[0], ground_truth[0])) / area(union(detection[0], ground_truth[0])) return iou
def time_union_prec2(self): pygeos.union(self.left, self.right, grid_size=2)
def time_union(self): pygeos.union(self.left, self.right)
def test_union(): poly1, poly2 = pygeos.box(0, 0, 10, 10), pygeos.box(10, 0, 20, 10) actual = pygeos.union(poly1, poly2) expected = pygeos.box(0, 0, 20, 10) assert pygeos.equals(actual, expected)