-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement torchvision operator
nms
| feat(torchlib) (#1253)
- Create the scaffold and tests to support torchvision ops. - Implement `torchvision::nms`
- Loading branch information
1 parent
3b2291c
commit 5b9c318
Showing
6 changed files
with
71 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. | ||
# -------------------------------------------------------------------------- | ||
# mypy: disable-error-code="misc,arg-type,type-arg,valid-type,assignment,return-value" | ||
"""torchvision operators.""" | ||
from __future__ import annotations | ||
|
||
from onnxscript.function_libs.torch_lib.registration import torch_op | ||
from onnxscript.onnx_opset import opset18 as op | ||
from onnxscript.onnx_types import FLOAT, INT64 | ||
|
||
_INT64_MAX = 0x7FFFFFFFFFFFFFFF | ||
|
||
|
||
@torch_op("torchvision::nms") | ||
def torchvision_nms(boxes: FLOAT, scores: FLOAT, iou_threshold: float) -> INT64: | ||
# boxes: [num_batches, spatial_dimension, 4] | ||
boxes = op.Unsqueeze(boxes, [0]) | ||
# scores: [num_batches, num_classes, spatial_dimension] | ||
scores = op.Unsqueeze(scores, [0, 1]) | ||
# nms_out: [num_selected_indices, 3] where each column is [batch_index, class_index, box_index] | ||
nms_out = op.NonMaxSuppression(boxes, scores, _INT64_MAX, iou_threshold) | ||
return op.Reshape(op.Slice(nms_out, axes=[1], starts=[2], ends=[3]), [-1]) |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
--index-url=https://download.pytorch.org/whl/nightly/cpu | ||
--pre | ||
torch | ||
torchvision |