forked from ivy-llc/ivy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added non_max_supression to ivy (ivy-llc#23668)
- Loading branch information
1 parent
d5d9a61
commit a034740
Showing
12 changed files
with
212 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,6 @@ | |
"mxnet" | ||
], | ||
"torch": [ | ||
"torch-scatter" | ||
"torch-scatter", "torchvision" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
ivy/functional/backends/torch/sub_backends/torchvision/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# import torchvision | ||
|
||
from . import layers | ||
from .layers import * | ||
|
||
|
||
name = "torchvision" | ||
|
||
incompatible_sub_backends = () |
37 changes: 37 additions & 0 deletions
37
ivy/functional/backends/torch/sub_backends/torchvision/layers.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from torchvision.ops import nms as torch_nms | ||
import torch | ||
|
||
|
||
def nms( | ||
boxes, | ||
scores=None, | ||
iou_threshold=0.5, | ||
max_output_size=None, | ||
score_threshold=float("-inf"), | ||
): | ||
# boxes (Tensor[N, 4])) – boxes to perform NMS on. | ||
# They are expected to be in (x1, y1, x2, y2) format | ||
# with 0 <= x1 < x2 and 0 <= y1 < y2. | ||
change_id = False | ||
if score_threshold is not float("-inf") and scores is not None: | ||
keep_idx = scores > score_threshold | ||
boxes = boxes[keep_idx] | ||
scores = scores[keep_idx] | ||
change_id = True | ||
nonzero = torch.nonzero(keep_idx).flatten() | ||
|
||
if scores is None: | ||
scores = torch.ones((boxes.shape[0],), dtype=boxes.dtype) | ||
|
||
if len(boxes) < 2: | ||
if len(boxes) == 1: | ||
ret = torch.tensor([0], dtype=torch.int64) | ||
else: | ||
ret = torch.tensor([], dtype=torch.int64) | ||
else: | ||
ret = torch_nms(boxes, scores, iou_threshold) | ||
|
||
if change_id and len(ret) > 0: | ||
ret = torch.tensor(nonzero[ret], dtype=torch.int64).flatten() | ||
|
||
return ret.flatten()[:max_output_size] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,4 @@ autoflake # for backend generation | |
snakeviz # for profiling | ||
cryptography | ||
xgboost | ||
torchvision |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ pandas | |
pyspark | ||
autoflake # for backend generation | ||
snakeviz # for profiling | ||
torchvision |