-
-
Notifications
You must be signed in to change notification settings - Fork 56.2k
readNetFromONNX: Cant create layer of type 'Exp' in getLayerInstance #18088
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You can try to create custom layer like this: import cv2 as cv
import numpy as np
class ExpLayer(object):
def __init__(self, params, blobs):
super(ExpLayer, self).__init__()
def getMemoryShapes(self, inputs):
return inputs
def forward(self, inputs):
return [np.exp(inputs[0])]
cv.dnn_registerLayer('Exp', ExpLayer) |
@l-bat Thanks for the suggestion. I am programming in C++, do you maybe have a hint for me how I could try the same in C++? |
We are executing the model on the GPU. Is my assumption right that by writing such a custom layer in simple C++, the execution for it would jump back to CPU? |
That's right. For more optimal implementaion of SSD, use PyTorch |
@dkurt Hi, as you suggested using PyTorch's |
@fengyuentau, https://pytorch.org/docs/stable/onnx.html#custom-operators. It creates just a node with specific inputs and parameters in ONNX format. Then you can parse ONNX as you want. You may find some other simple examples here: https://github.com/dkurt/openvino_pytorch_layers/ |
@dkurt thanks very much! I'll give it a try. |
@dkurt I have some questions for your solution to add the 'DetectionOutput' node into the ONNX model:
BTW, I tried to add the 'DetectionOutput' layer to my onnx model following this guide (https://pytorch.org/docs/stable/onnx.html#custom-operators), but failed because I thought I can leave the actual op unimplemented and only add the node, which turns out to be wrong (https://pytorch.org/tutorials/advanced/torch_script_custom_ops.html). |
@fengyuentau, symbolic should have
I've tried only torch.autograd.Function. Then you can wrap it into the Module but symbolic op should be used by |
Detailed description
Very similar issue: #15244
@dkurt
Basically, I exported a ssdlite-mobilenetv3 in PyTorch to ONNX format. Loading it in OpenCV leads to this error:
create detection model: OpenCV(4.4.0-dev) /tmp/opencv/opencv/modules/dnn/src/dnn.cpp:604: error: (-2:Unspecified error) Can't create layer "1117" of type "Exp" in function 'getLayerInstance'
Enabling
fusion
did not solve my issue.Here is the code I used to export the model:
Here is my PyTorch model (mb3-ssd-lite.pth.txt) and converted ONNX model (mb3-ssd-lite.onnx.txt)
The text was updated successfully, but these errors were encountered: