Skip to content

Commit

Permalink
Add Non-Maximum Suppression (NMS) inplace flag (ultralytics#8368)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlainSchoebi authored and gkinman committed May 30, 2024
1 parent fd92443 commit a384e59
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions ultralytics/utils/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def non_max_suppression(
max_time_img=0.05,
max_nms=30000,
max_wh=7680,
in_place=True,
rotated=False,
):
"""
Expand All @@ -197,7 +198,8 @@ def non_max_suppression(
nc (int, optional): The number of classes output by the model. Any indices after this will be considered masks.
max_time_img (float): The maximum time (seconds) for processing one image.
max_nms (int): The maximum number of boxes into torchvision.ops.nms().
max_wh (int): The maximum box width and height in pixels
max_wh (int): The maximum box width and height in pixels.
in_place (bool): If True, the input prediction tensor will be modified in place.
Returns:
(List[torch.Tensor]): A list of length batch_size, where each element is a tensor of
Expand All @@ -224,7 +226,10 @@ def non_max_suppression(

prediction = prediction.transpose(-1, -2) # shape(1,84,6300) to shape(1,6300,84)
if not rotated:
prediction[..., :4] = xywh2xyxy(prediction[..., :4]) # xywh to xyxy
if in_place:
prediction[..., :4] = xywh2xyxy(prediction[..., :4]) # xywh to xyxy
else:
prediction = torch.cat((xywh2xyxy(prediction[..., :4]), prediction[..., 4:]), dim=-1) # xywh to xyxy

t = time.time()
output = [torch.zeros((0, 6 + nm), device=prediction.device)] * bs
Expand Down

0 comments on commit a384e59

Please sign in to comment.