You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DNN: Required argument "split" not found into dictionary #16370
I'm trying to inference classification model trained on Custom Vision of Azure Cognitive Services using OpenCV DNN module.
Custom Vision can download trained ONNX model. The following error occurs when read net from it.
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(4.2.0) Error: Requested object was not found (Required argument "split" not found into dictionary) in cv::dnn::dnn4_v20191202::Dict::get, file C:\opencv-4.2.0\modules\dnn\include\opencv2/dnn/dnn.inl.hpp, line 349
This is part of model visualize image using Netron.
(Other model visualize image is here. All model visualize image is here.)
What do you think? Thanks,
Steps to reproduce
This issue can be reproduced with the following code:
const std::string model = "./model.onnx";
cv::dnn::Net net = cv::dnn::readNet( model ); // error
changed the title [-]Required argument "split" not found into dictionary[/-][+]DNN: Required argument "split" not found into dictionary[/+]on Jan 21, 2020
// opencv_debug.cpp
#include<opencv2/dnn.hpp>intmain()
{
const std::string model = "./model.onnx";
cv::dnn::Net net = cv::dnn::readNet( model ); // error
}
I used, g++ opencv_debug.cpp -o issue_16370 -lopencv_dnn -lopencv_core and got the following,
terminate called after throwing an instance of 'cv::Exception' what(): OpenCV(3.4.9-dev) /home/czgdp1807/opencv_project/opencv/modules/dnn/include/opencv2/dnn/dnn.inl.hpp:333: error: (-204:Requested object was not found) Required argument "split"not found into dictionary in function 'get'Aborted (core dumped)
Can I start working on this issue as it appears that no PR has referenced this issue.
I was trying to find the cause of the bug and observed that the corner case of absence of split attribute in Split layer in the code base wasn't handled and therefore the above exception is thrown. We don't need split attribute, if it is not present then the input tensor is split into equal sized parts. I will make a PR for this issue by tomorrow(in IST). @UnaNancyOwen Please let me know the expected output in your case so that I can add tests for the fix accordingly. Thank you.
"Expected output" is handling ONNX operation properly (including its possible parameters/inputs/modes).
Documentation about ONNX Split operation is here.
Some of ONNX testdata cases are generated through this script (using PyTorch and exporting to ONNX).
@UnaNancyOwen I have described some problems which I am facing while resolving this issue in #16424 (comment)
There is Constant layer in the model which is having string_data with black-keyboard entry twice. Can you please tell what's the purpose of these two entries? However, the tensor is having sizes. So, I think the tensor is not empty. Waiting for your response. Thank you.
@czgdp1807 Thanks for working on this issue.
Sorry, I can't answer your question. I don't know the details of this model that was defined in Custom Vision. (Unfortunately, I don't have enough knowledge about deep learning to understand model. 🙇♂️)
@UnaNancyOwen Thanks for the updates. Though I am sure that bug in processing of Split layer has been fixed. I will try to fix the problems with Constant layer as soon as possible.
Hi @alalek@UnaNancyOwen ,
I parsed the model using python package, onnx and observed that this model outputsstring instead of a probability vector. In fact, the Constant, a.k.a. LabelLoader in the attached svg, layer in @UnaNancyOwen 's model contains the names of various labels which are extracted using the Labeld and is done by the LabelIndexExtractor. Then the output of LabelLoader and LabelIndexExtractor are given to LabelSelector which returns the final class label in the form of a string.
Various Fixes
To fix the Constant layer we have to provide support for tensor(string) as it is included in type constraints for Constant layer. For that we have to provide support for strings in Mat because blobs data member of ConstLayer are a vector of Mat.
Another approach can be, to change functions like getMatFromTensor, getMemoryShapes for making them compatible with tensor(string).
There can be other good approaches too.
What to do for now?
In my ongoing PR #16424 I will add a test for Split layer and complete it so that Split layer works properly. Alongside, I will open an issue for discussing other fixes for supporting tensor(string) types in Constant layer. In case if anyone can suggest a quick fix for supporting tensor(string) then I will include them in my going PR itself.
Please let me know if I have misinterpreted anything. Thanks.
@UnaNancyOwen The fix for split layer has been made. Please follow the suggestion at #16424 (comment) to verify. Please let me know if it's working for you.
@czgdp1807 Thanks, I tried it but got the following error instead of the previous one. (#16424 was merged into the 3.4 branch, so I tried with 3.4/HEAD.)
OpenCV: terminate handler is called! The last OpenCV error is:
OpenCV(3.4.9-dev) Error: Assertion failed (!tensor_proto.raw_data().empty() || !tensor_proto.float_data().empty() || !tensor_proto.double_data().empty() || !tensor_proto.int64_data().empty()) in cv::dnn::experimental_dnn_34_v16::getMatFromTensor, file C:\opencv\modules\dnn\src\onnx\onnx_importer.cpp, line 112
Activity
alalek commentedon Jan 17, 2020
Could you please attach .onnx model file (google drive link or attach .zip file) which can be used to reproduce problem? (you may use random weighs)
UnaNancyOwen commentedon Jan 17, 2020
model.onnx can be downloaded from here. (zip file)
[-]Required argument "split" not found into dictionary[/-][+]DNN: Required argument "split" not found into dictionary[/+]czgdp1807 commentedon Jan 22, 2020
Hi @UnaNancyOwen @alalek
I think I am able to reproduce the error.
Code
I used,
g++ opencv_debug.cpp -o issue_16370 -lopencv_dnn -lopencv_coreand got the following,Can I start working on this issue as it appears that no PR has referenced this issue.
alalek commentedon Jan 22, 2020
@czgdp1807 Yes =)
czgdp1807 commentedon Jan 23, 2020
I was trying to find the cause of the bug and observed that the corner case of absence of
splitattribute inSplitlayer in the code base wasn't handled and therefore the above exception is thrown. We don't needsplitattribute, if it is not present then the input tensor is split into equal sized parts. I will make a PR for this issue by tomorrow(in IST).@UnaNancyOwen Please let me know the expected output in your case so that I can add tests for the fix accordingly. Thank you.
alalek commentedon Jan 23, 2020
@czgdp1807 Thank you for looking on this!
"Expected output" is handling ONNX operation properly (including its possible parameters/inputs/modes).
Documentation about ONNX Split operation is here.
Some of ONNX testdata cases are generated through this script (using PyTorch and exporting to ONNX).
czgdp1807 commentedon Jan 24, 2020
@UnaNancyOwen I have described some problems which I am facing while resolving this issue in #16424 (comment)
There is
Constantlayer in the model which is havingstring_datawithblack-keyboardentry twice. Can you please tell what's the purpose of these two entries? However, the tensor is havingsizes. So, I think the tensor is not empty. Waiting for your response. Thank you.UnaNancyOwen commentedon Jan 25, 2020
@czgdp1807 Thanks for working on this issue.
Sorry, I can't answer your question. I don't know the details of this model that was defined in Custom Vision. (Unfortunately, I don't have enough knowledge about deep learning to understand model. 🙇♂️)
czgdp1807 commentedon Jan 25, 2020
@UnaNancyOwen Thanks for the updates. Though I am sure that bug in processing of
Splitlayer has been fixed. I will try to fix the problems withConstantlayer as soon as possible.czgdp1807 commentedon Jan 27, 2020
Hi @alalek @UnaNancyOwen ,
I parsed the model using python package,
onnxand observed that this model outputsstringinstead of a probability vector. In fact, theConstant, a.k.a.LabelLoaderin the attached svg, layer in @UnaNancyOwen 's model contains the names of various labels which are extracted using theLabeldand is done by theLabelIndexExtractor. Then the output ofLabelLoaderandLabelIndexExtractorare given toLabelSelectorwhich returns the final class label in the form of a string.Various Fixes
To fix the
Constantlayer we have to provide support fortensor(string)as it is included in type constraints forConstantlayer. For that we have to provide support for strings inMatbecauseblobsdata member ofConstLayerare a vector ofMat.Another approach can be, to change functions like
getMatFromTensor,getMemoryShapesfor making them compatible withtensor(string).There can be other good approaches too.
What to do for now?
In my ongoing PR #16424 I will add a test for Split layer and complete it so that
Splitlayer works properly. Alongside, I will open an issue for discussing other fixes for supportingtensor(string)types inConstantlayer. In case if anyone can suggest a quick fix for supportingtensor(string)then I will include them in my going PR itself.Please let me know if I have misinterpreted anything. Thanks.
czgdp1807 commentedon Feb 15, 2020
@UnaNancyOwen The fix for split layer has been made. Please follow the suggestion at #16424 (comment) to verify. Please let me know if it's working for you.
UnaNancyOwen commentedon Feb 16, 2020
@czgdp1807 Thanks, I tried it but got the following error instead of the previous one. (#16424 was merged into the 3.4 branch, so I tried with 3.4/HEAD.)
czgdp1807 commentedon Feb 16, 2020
Yes that will happen as string isn't supported by
Constantlayer. You should makeSoftMaxas output layer.UnaNancyOwen commentedon Feb 17, 2020
Does that mean changing the model?
czgdp1807 commentedon Feb 17, 2020
IMO, the trick is mentioned at #16424 (comment)