def test_ious(): b1 = [[10, 20]] b2 = [[10, 21], [30, 40]] iou_1d = calculate_iou(b1, b2, dim=1) assert_almost_equal(iou_1d, np.array([[0.9091, 0.]])) b1 = [[20.1, 20.1, 30.1, 30.1], [15, 15, 25, 25]] b2 = [[10, 10, 20, 20]] iou_2d = calculate_iou(b1, b2, dim=2) assert_almost_equal(iou_2d, [[0], [0.1429]]) b1 = [[10, 10, 10, 20, 20, 20]] b2 = [[10, 11, 10.2, 21, 19.9, 20.3], [30, 30, 30, 90, 90, 90]] iou_3d = calculate_iou(b1, b2, dim=3) assert_almost_equal(iou_3d, [[0.7811, 0]])
def cost_matrix_iou_feature(trackers: Sequence[Tracker], detections: Sequence[Detection], feature_similarity_fn=angular_similarity, feature_similarity_beta: float = None): # boxes b1 = np.array([t.box for t in trackers]) b2 = np.array([d.box for d in detections]) # box iou inferred_dim = int(len(b1[0]) / 2) iou_mat = calculate_iou(b1, b2, dim=inferred_dim) # feature similarity if feature_similarity_beta is not None: # get features f1 = [t.feature for t in trackers] f2 = [d.feature for d in detections] if _sequence_has_none(f1) or _sequence_has_none(f2): # fallback to pure IOU due to missing features apt_mat = iou_mat else: sim_mat = feature_similarity_fn(f1, f2) sim_mat = feature_similarity_beta + ( 1 - feature_similarity_beta) * sim_mat # combined aptitude apt_mat = np.multiply(iou_mat, sim_mat) else: apt_mat = iou_mat cost_mat = -1.0 * apt_mat return cost_mat, iou_mat
def test_ious_large(): # benchmarking test t = current_milli_time() for _ in range(100): b1 = np.random.randn(30, 4) b2 = np.random.randn(20, 4) iou = calculate_iou(b1, b2, dim=2) assert iou.shape == (30, 20) tdiff = current_milli_time() - t assert tdiff < 100