diff --git a/bindings/python/powerboxes/__init__.py b/bindings/python/powerboxes/__init__.py index f9d0e74..0d69e6a 100644 --- a/bindings/python/powerboxes/__init__.py +++ b/bindings/python/powerboxes/__init__.py @@ -136,7 +136,7 @@ def parallel_iou_distance( raise TypeError(_BOXES_NOT_NP_ARRAY) if boxes1.dtype == boxes2.dtype: try: - return _dtype_to_func_parallel_iou_distance[boxes1.dtype](boxes1, boxes2) + return _dtype_to_func_parallel_iou_distance[boxes1.dtype](boxes1, boxes2) # type: ignore except KeyError: raise TypeError( f"Box dtype: {boxes1.dtype} not in supported dtypes {supported_dtypes}" @@ -167,7 +167,7 @@ def parallel_giou_distance( raise TypeError(_BOXES_NOT_NP_ARRAY) if boxes1.dtype == boxes2.dtype: try: - return _dtype_to_func_parallel_giou_distance[boxes1.dtype](boxes1, boxes2) + return _dtype_to_func_parallel_giou_distance[boxes1.dtype](boxes1, boxes2) # type: ignore except KeyError: raise TypeError( f"Box dtype: {boxes1.dtype} not in supported dtypes {supported_dtypes}" @@ -198,7 +198,7 @@ def giou_distance( raise TypeError(_BOXES_NOT_NP_ARRAY) if boxes1.dtype == boxes2.dtype: try: - return _dtype_to_func_giou_distance[boxes1.dtype](boxes1, boxes2) + return _dtype_to_func_giou_distance[boxes1.dtype](boxes1, boxes2) # type: ignore except KeyError: raise TypeError( f"Box dtype: {boxes1.dtype} not in supported dtypes {supported_dtypes}" @@ -229,7 +229,7 @@ def tiou_distance( raise TypeError(_BOXES_NOT_NP_ARRAY) if boxes1.dtype == boxes2.dtype: try: - return _dtype_to_func_tiou_distance[boxes1.dtype](boxes1, boxes2) + return _dtype_to_func_tiou_distance[boxes1.dtype](boxes1, boxes2) # type: ignore except KeyError: raise TypeError( f"Box dtype: {boxes1.dtype} not in supported dtypes {supported_dtypes}" @@ -346,7 +346,7 @@ def remove_small_boxes(boxes: npt.NDArray[T], min_size: float) -> npt.NDArray[T] if not isinstance(boxes, np.ndarray): raise TypeError(_BOXES_NOT_NP_ARRAY) try: - return _dtype_to_func_remove_small_boxes[boxes.dtype](boxes, min_size) + return _dtype_to_func_remove_small_boxes[boxes.dtype](boxes, min_size) # type: ignore except KeyError: raise TypeError( f"Box dtype: {boxes.dtype} not in supported dtypes {supported_dtypes}" @@ -365,7 +365,7 @@ def boxes_areas(boxes: npt.NDArray[T]) -> npt.NDArray[np.float64]: if not isinstance(boxes, np.ndarray): raise TypeError(_BOXES_NOT_NP_ARRAY) try: - return _dtype_to_func_box_areas[boxes.dtype](boxes) + return _dtype_to_func_box_areas[boxes.dtype](boxes) # type: ignore except KeyError: raise TypeError( f"Box dtype: {boxes.dtype} not in supported dtypes {supported_dtypes}" @@ -391,7 +391,7 @@ def box_convert(boxes: npt.NDArray[T], in_fmt: str, out_fmt: str) -> npt.NDArray if not isinstance(boxes, np.ndarray): raise TypeError(_BOXES_NOT_NP_ARRAY) try: - return _dtype_to_func_box_convert[boxes.dtype](boxes, in_fmt, out_fmt) + return _dtype_to_func_box_convert[boxes.dtype](boxes, in_fmt, out_fmt) # type: ignore except KeyError: raise TypeError( f"Box dtype: {boxes.dtype} not in supported dtypes {supported_dtypes}" @@ -438,7 +438,7 @@ def nms( if not isinstance(boxes, np.ndarray) or not isinstance(scores, np.ndarray): raise TypeError("Boxes and scores must be numpy arrays") try: - return _dtype_to_func_nms[boxes.dtype]( + return _dtype_to_func_nms[boxes.dtype]( # type: ignore boxes, scores, iou_threshold, score_threshold ) except KeyError: @@ -473,7 +473,7 @@ def rtree_nms( if not isinstance(boxes, np.ndarray) or not isinstance(scores, np.ndarray): raise TypeError("Boxes and scores must be numpy arrays") try: - return _dtype_to_func_rtree_nms[boxes.dtype]( + return _dtype_to_func_rtree_nms[boxes.dtype]( # type: ignore boxes, scores, iou_threshold, score_threshold ) except KeyError: diff --git a/bindings/tests/test_boxes.py b/bindings/tests/test_boxes.py index 1fe38d5..fe5b27f 100644 --- a/bindings/tests/test_boxes.py +++ b/bindings/tests/test_boxes.py @@ -1,7 +1,8 @@ -from powerboxes import masks_to_boxes -import numpy as np import os + +import numpy as np from PIL import Image +from powerboxes import masks_to_boxes def test_masks_box(): diff --git a/powerboxesrs/src/boxes.rs b/powerboxesrs/src/boxes.rs index 3cecf14..bf5bcfe 100644 --- a/powerboxesrs/src/boxes.rs +++ b/powerboxesrs/src/boxes.rs @@ -32,7 +32,7 @@ pub enum BoxFormat { /// ``` pub fn box_areas<'a, N, BA>(boxes: BA) -> Array1 where - N: Num + PartialEq + PartialOrd + ToPrimitive + Copy + 'a, + N: Num + PartialEq + ToPrimitive + Copy + 'a, BA: Into>, { let boxes = boxes.into(); diff --git a/powerboxesrs/src/diou.rs b/powerboxesrs/src/diou.rs index 6981ee6..a2f0418 100644 --- a/powerboxesrs/src/diou.rs +++ b/powerboxesrs/src/diou.rs @@ -52,7 +52,7 @@ where let intersection = (x2 - x1) * (y2 - y1); let intersection = intersection.to_f64().unwrap(); let intersection = utils::min(intersection, utils::min(area1, area2)); - let iou = intersection / (area1 + area2 - intersection + utils::EPS); + let iou = intersection / (area1 + area2 - intersection); let center_box1 = [(a1_x1 + a1_x2) / two, (a1_y1 + a1_y2) / two]; let center_box2 = [(a2_x1 + a2_x2) / two, (a2_y1 + a2_y2) / two]; diff --git a/powerboxesrs/src/giou.rs b/powerboxesrs/src/giou.rs index 232c766..449207b 100644 --- a/powerboxesrs/src/giou.rs +++ b/powerboxesrs/src/giou.rs @@ -69,7 +69,7 @@ where let intersection = (x2 - x1) * (y2 - y1); let intersection = intersection.to_f64().unwrap(); let intersection = utils::min(intersection, utils::min(area1, area2)); - let union = area1 + area2 - intersection + utils::EPS; + let union = area1 + area2 - intersection; (intersection / union, union) }; // Calculate the enclosing box (C) coordinates @@ -152,7 +152,7 @@ where let intersection = (x2 - x1) * (y2 - y1); let intersection = intersection.to_f64().unwrap(); let intersection = utils::min(intersection, utils::min(area1, area2)); - let union = area1 + area2 - intersection + utils::EPS; + let union = area1 + area2 - intersection; (intersection / union, union) }; // Calculate the enclosing box (C) coordinates @@ -254,7 +254,7 @@ where let rect1 = boxes1_rects[box1.index]; let rect2 = boxes2_rects[box2.index]; let intersection = intersection_area(&rect1, &rect2); - let union = area1 + area2 - intersection + utils::EPS; + let union = area1 + area2 - intersection; // Calculate the enclosing box (C) coordinates let c_x1 = utils::min(box1.x1, box2.x1); let c_y1 = utils::min(box1.y1, box2.y1); diff --git a/powerboxesrs/src/iou.rs b/powerboxesrs/src/iou.rs index 950962c..2547ae8 100644 --- a/powerboxesrs/src/iou.rs +++ b/powerboxesrs/src/iou.rs @@ -66,8 +66,7 @@ where let intersection = (x2 - x1) * (y2 - y1); let intersection = intersection.to_f64().unwrap(); let intersection = utils::min(intersection, utils::min(area1, area2)); - iou_matrix[[i, j]] = - utils::ONE - (intersection / (area1 + area2 - intersection + utils::EPS)); + iou_matrix[[i, j]] = utils::ONE - (intersection / (area1 + area2 - intersection)); } } @@ -137,7 +136,7 @@ where let intersection = (x2 - x1) * (y2 - y1); let intersection = intersection.to_f64().unwrap(); let intersection = utils::min(intersection, utils::min(area1, area2)); - *d = 1. - (intersection / (area1 + area2 - intersection + utils::EPS)); + *d = 1. - (intersection / (area1 + area2 - intersection)); } }); }); @@ -217,7 +216,7 @@ where let area1 = areas1[box1.index]; let area2 = areas2[box2.index]; let intersection = intersection_area(&boxes1_rects[box1.index], &boxes2_rects[box2.index]); - let union = area1 + area2 - intersection + utils::EPS; + let union = area1 + area2 - intersection; iou_matrix[[box1.index, box2.index]] = utils::ONE - intersection / union; } diff --git a/powerboxesrs/src/utils.rs b/powerboxesrs/src/utils.rs index 91c8322..c40c183 100644 --- a/powerboxesrs/src/utils.rs +++ b/powerboxesrs/src/utils.rs @@ -1,7 +1,6 @@ use num_traits::{Num, ToPrimitive}; use rstar::{RStarInsertionStrategy, RTreeNum, RTreeObject, RTreeParams, AABB}; -pub const EPS: f64 = 1e-16; pub const ONE: f64 = 1.0; pub const ZERO: f64 = 0.0;