-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from sony/indices
[torch] add multiclass_nms_with_indices layer
- Loading branch information
Showing
14 changed files
with
1,310 additions
and
541 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
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,53 @@ | ||
# ----------------------------------------------------------------------------- | ||
# Copyright 2024 Sony Semiconductor Israel, Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ----------------------------------------------------------------------------- | ||
from typing import Callable | ||
|
||
import torch | ||
|
||
from sony_custom_layers.util.import_util import is_compatible | ||
|
||
CUSTOM_LIB_NAME = 'sony' | ||
custom_lib = torch.library.Library(CUSTOM_LIB_NAME, "DEF") | ||
|
||
|
||
def get_op_qualname(torch_op_name): | ||
""" Op qualified name """ | ||
return CUSTOM_LIB_NAME + '::' + torch_op_name | ||
|
||
|
||
def register_op(torch_op_name: str, schema: str, impl: Callable): | ||
""" | ||
Register torch custom op under the custom library. | ||
Args: | ||
torch_op_name: op name to register. | ||
schema: schema for the custom op. | ||
impl: implementation of the custom op. | ||
Returns: | ||
Custom op qualified name. | ||
""" | ||
torch_op_qualname = get_op_qualname(torch_op_name) | ||
|
||
custom_lib.define(schema) | ||
|
||
if is_compatible('torch>=2.2'): | ||
register_impl = torch.library.impl(torch_op_qualname, 'default') | ||
else: | ||
register_impl = torch.library.impl(custom_lib, torch_op_name) | ||
register_impl(impl) | ||
|
||
return torch_op_qualname |
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
Oops, something went wrong.