Skip to content

V2.0 add bbox ordering #857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b1ada49
update version (#854)
fcakyon Mar 24, 2023
1a7da13
update version (#854)
fcakyon Mar 24, 2023
47d14a3
update version (#854)
MLDovakin Mar 25, 2023
3a6bf92
Merge remote-tracking branch 'origin/v2.0_add_bbox_ordering' into v2.…
MLDovakin Mar 25, 2023
dfb96ea
Merge branch 'main' into v2.0_add_bbox_ordering
MLDovakin Mar 25, 2023
828de94
Update predict.py
MLDovakin Mar 26, 2023
d3ac5d3
Merge branch 'main' into v2.0_add_bbox_ordering
MLDovakin Mar 29, 2023
0846a94
Merge branch 'main' into v2.0_add_bbox_ordering
MLDovakin May 27, 2023
abb4bf1
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Nov 5, 2023
fd2ebfa
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Nov 5, 2023
440db21
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Nov 5, 2023
9062f4b
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Nov 6, 2023
e2a6e64
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Nov 6, 2023
1841be5
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Apr 22, 2024
a543002
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Apr 29, 2024
9a828d8
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon May 20, 2024
2315781
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Jun 2, 2024
367d648
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Jun 2, 2024
fe2378f
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Jun 2, 2024
f19f40c
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Jun 22, 2025
b1235da
Merge branch 'main' into v2.0_add_bbox_ordering
fcakyon Jun 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions sahi/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,11 @@ def bbox_sort(a, b, thresh):
return bbox_a[1] - bbox_b[1]


def agg_prediction(result: PredictionResult, thresh):
def agg_prediction(thresh, result: PredictionResult):
coord_list = []
res = result.to_coco_annotations()
res = result.object_prediction_list
for ann in res:
current_bbox = ann["bbox"]
current_bbox = ann.bbox.to_xywh()
x = current_bbox[0]
y = current_bbox[1]
w = current_bbox[2]
Expand All @@ -370,7 +370,7 @@ def agg_prediction(result: PredictionResult, thresh):
coord_list.append((x, y, w, h))
cnts = sorted(coord_list, key=cmp_to_key(lambda a, b: bbox_sort(a, b, thresh)))
for pred in range(len(res) - 1):
res[pred]["image_id"] = cnts.index(tuple(res[pred]["bbox"]))
res[pred].category.id = cnts.index(tuple(res[pred].bbox.to_xywh()))

return res

Expand All @@ -396,6 +396,7 @@ def predict(
postprocess_match_metric: str = "IOS",
postprocess_match_threshold: float = 0.5,
postprocess_class_agnostic: bool = False,
use_bbox_agg_thrsh: int = None,
novisual: bool = False,
view_video: bool = False,
frame_skip_interval: int = 0,
Expand Down Expand Up @@ -470,6 +471,8 @@ def predict(
postprocessed after sliced prediction.
postprocess_class_agnostic: bool
If True, postprocess will ignore category ids.
use_bbox_agg_thrsh: int
If not None orders bboxes ids in object_prediction_list
novisual: bool
Dont export predicted video/image visuals.
view_video: bool
Expand Down Expand Up @@ -619,6 +622,8 @@ def predict(
exclude_classes_by_id=exclude_classes_by_id,
)
object_prediction_list = prediction_result.object_prediction_list
if use_bbox_agg_thrsh is not None:
object_prediction_list = agg_prediction(use_bbox_agg_thrsh, prediction_result)
if prediction_result.durations_in_seconds:
durations_in_seconds["slice"] += prediction_result.durations_in_seconds["slice"]
else:
Expand Down
Loading