Issue 1:
I implemented the custom operator that named 'test_custom' with reference to torch_script_custom_ops，then I convert the pytorch model to onnx，

When I load the onnx model by dnn module, I have get the following error.

System information

OS Platform and Distribution (Windows10):

ONNX Runtime installed from (pip install onnxruntime):

ONNX Runtime version:(1.9.0)

ONNX version : (1.10.2)

Python version: 3.7.4

Visual Studio version (2019):

OpenCV: 4.2.0

The step and code:

**step1: ** Implemented the custom ops in C++, test.cpp

#include "torch/script.h"

torch::Tensor test_custom(torch::Tensor image, torch::Tensor warp) {
return image.clone();
}

static auto registry = torch::RegisterOperators("my_ops::test_custom", &test_custom);

**step2: ** Compiled my code by Cmake and get the shared library: test_custom.dll, CMakeLists.txt

cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(test_custom)

set(CMAKE_VERBOSE_MAKEFILE ON)

# Torch
set(TORCH_ROOT "D:/python/Lib/site-packages/torch")
include_directories(${TORCH_ROOT}/include)
link_directories(${TORCH_ROOT}/lib/)

# Define our library target
add_library(${PROJECT_NAME} SHARED test.cpp)

# Enable C++14
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

# Link against Torch
target_link_libraries(${PROJECT_NAME}
c10
torch_cpu
)

**step3: ** export the pytorch model to onnx

import torch
torch.ops.load_library("test_custom.dll")

class MyNet(torch.nn.Module):
def __init__(self, num_classes):
super(MyNet, self).__init__()
self.num_classes = num_classes

def forward(self, xyz, other):
return torch.ops.my_ops.test_custom(xyz, other)

def my_custom(g, xyz, other):
return g.op("my_ops::test_custom", xyz, other)
torch.onnx.register_custom_op_symbolic("my_ops::test_custom", my_custom, 9)

if __name__ == "__main__":
net = MyNet(2)
xyz = torch.rand((2, 3))
other = torch.rand((1, 3))

print("xyz: ", xyz)
out = net(xyz, other)
print("out: ", out)

# export onnx
torch.onnx.export(net,
(xyz, other),
"./model.onnx",
input_names=["points", "cate"],
output_names=["cls_prob"],
custom_opsets={"my_ops": 11},
dynamic_axes={
"points": {0: "channel", 1: "n_point"},
"cls_prob": {0: "channel", 1: "n"}
}
)

the model structure is as follows

**step4: ** call the onnx model by dnn

import cv2

# load model
onnx_path = "./model.onnx"
cv2.cv2.dnn.readNetFromONNX(onnx_path )

I want to know how to call the custom operator in dnn module? someone can help me?

Issue 2:
I implemented the custom operator that named 'test_custom' with reference to torch_script_custom_ops，then I convert the pytorch model to onnx，

When I load the onnx model by dnn module, I have get the following error.

System information

OS Platform and Distribution (Windows10):

ONNX Runtime installed from (pip install onnxruntime):

ONNX Runtime version:(1.9.0)

ONNX version : (1.10.2)

Python version: 3.7.4

Visual Studio version (2019):

GCC/Compiler version (if compiling from source):

CUDA/cuDNN version:

GPU model and memory: CPU only

OpenCV: 4.2.0

The step and code:

**step1: ** Implemented the custom ops in C++, test.cpp

#include "torch/script.h"

torch::Tensor test_custom(torch::Tensor image, torch::Tensor warp) {
return image.clone();
}

static auto registry = torch::RegisterOperators("my_ops::test_custom", &test_custom);

**step2: ** Compiled my code by Cmake and get the shared library: test_custom.dll, CMakeLists.txt

cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
project(test_custom)

set(CMAKE_VERBOSE_MAKEFILE ON)

# Torch
set(TORCH_ROOT "D:/python/Lib/site-packages/torch")
include_directories(${TORCH_ROOT}/include)
link_directories(${TORCH_ROOT}/lib/)

# Define our library target
add_library(${PROJECT_NAME} SHARED test.cpp)

# Enable C++14
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)

# Link against Torch
target_link_libraries(${PROJECT_NAME}
c10
torch_cpu
)

**step3: ** export the pytorch model to onnx

import torch
torch.ops.load_library("test_custom.dll")

class MyNet(torch.nn.Module):
def __init__(self, num_classes):
super(MyNet, self).__init__()
self.num_classes = num_classes

def forward(self, xyz, other):
return torch.ops.my_ops.test_custom(xyz, other)

def my_custom(g, xyz, other):
return g.op("my_ops::test_custom", xyz, other)
torch.onnx.register_custom_op_symbolic("my_ops::test_custom", my_custom, 9)

if __name__ == "__main__":
net = MyNet(2)
xyz = torch.rand((2, 3))
other = torch.rand((1, 3))

print("xyz: ", xyz)
out = net(xyz, other)
print("out: ", out)

# export onnx
torch.onnx.export(net,
(xyz, other),
"./model.onnx",
input_names=["points", "cate"],
output_names=["cls_prob"],
custom_opsets={"my_ops": 11},
dynamic_axes={
"points": {0: "channel", 1: "n_point"},
"cls_prob": {0: "channel", 1: "n"}
}
)

the model structure is as follows

**step4: ** call the onnx model by dnn

import cv2

# load model
onnx_path = "./model.onnx"
cv2.cv2.dnn.readNetFromONNX(onnx_path )

I want to know how to call the custom operator in dnn module?