Skip to content

DNN: Required argument "split" not found into dictionary #16370

Closed

Description

@UnaNancyOwen
System information (version)
  • OpenCV => 4.2.0
  • Operating System / Platform => Windows 64 Bit
  • Compiler => Visual Studio 2019
Detailed description

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.
2020-01-17_10h51_43
(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

Activity

  1. alalek commented on Jan 17, 2020

    @alalek
    Member

    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)

  2. UnaNancyOwen commented on Jan 17, 2020

    @UnaNancyOwen
    ContributorAuthor

    model.onnx can be downloaded from here. (zip file)

  3. changed the title [-]Required argument "split" not found into dictionary[/-] [+]DNN: Required argument "split" not found into dictionary[/+] on Jan 21, 2020
  4. czgdp1807 commented on Jan 22, 2020

    @czgdp1807
    Contributor

    Hi @UnaNancyOwen @alalek
    I think I am able to reproduce the error.
    Code

    // opencv_debug.cpp
    #include<opencv2/dnn.hpp>
    int main()
    {
        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.

  5. alalek commented on Jan 22, 2020

    @alalek
    Member

    @czgdp1807 Yes =)

  6. czgdp1807 commented on Jan 23, 2020

    @czgdp1807
    Contributor

    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.

  7. alalek commented on Jan 23, 2020

    @alalek
    Member

    @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).

  8. czgdp1807 commented on Jan 24, 2020

    @czgdp1807
    Contributor

    @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.

  9. UnaNancyOwen commented on Jan 25, 2020

    @UnaNancyOwen
    ContributorAuthor

    @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. 🙇‍♂️)

  10. czgdp1807 commented on Jan 25, 2020

    @czgdp1807
    Contributor

    @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.

  11. czgdp1807 commented on Jan 27, 2020

    @czgdp1807
    Contributor

    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.

  12. czgdp1807 commented on Feb 15, 2020

    @czgdp1807
    Contributor

    @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.

  13. UnaNancyOwen commented on Feb 16, 2020

    @UnaNancyOwen
    ContributorAuthor

    @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
    
  14. czgdp1807 commented on Feb 16, 2020

    @czgdp1807
    Contributor

    Yes that will happen as string isn't supported by Constant layer. You should make SoftMax as output layer.

  15. UnaNancyOwen commented on Feb 17, 2020

    @UnaNancyOwen
    ContributorAuthor

    Does that mean changing the model?

  16. czgdp1807 commented on Feb 17, 2020

    @czgdp1807
    Contributor

    IMO, the trick is mentioned at #16424 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcategory: dnnconfirmed

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions