Skip to content
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

V2.0 add bbox ordering #857

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
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 @@ -321,11 +321,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 @@ -334,7 +334,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 @@ -360,6 +360,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 @@ -432,6 +433,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 @@ -571,6 +574,8 @@ def predict(
verbose=1 if verbose else 0,
)
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)
durations_in_seconds["slice"] += prediction_result.durations_in_seconds["slice"]
else:
# get standard prediction
Expand Down