Skip to content
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

Open CV will not infere more than 2 models when cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_VERBOSE); is set #24041

Closed
4 tasks done
ukoehler opened this issue Jul 21, 2023 · 5 comments · Fixed by #24156
Assignees
Milestone

Comments

@ukoehler
Copy link

System Information

OpenCV 4.7.0 and 4.8.0 compiled from source
Operating system: various Linux versions
Compiler: gcc5, gcc7 and gcc11

Detailed description

Took me a whole week to investigate #23982 and found a very bizzare behaviour that nobody will easily expect.

When infering DNNs everything is ok, as long as I infere the same model several times (I tried up to 3). However, the problem start when infering different models. With standard logging, still, everything works fine.

However, when cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_VERBOSE); is used (I use that to ensure my build of OpenCV is actually multi-threading on various platforms), the third inference stops working reproducibly . The provided code as 4 net and commenting inferences shows that the concrete model does not seem to matter.

Steps to reproduce

The problem is reproducible and enforceable.

The code used:

#include "opencv2/opencv.hpp"
#include "opencv2/core/utils/logger.hpp"

        cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_VERBOSE);
        std::string alexnetModelConfiguration = R"(/build/uk/source/ovtest/deploy_alexnet_places365.prototxt)";
        std::string alexnetModelWeights = R"(/build/uk/source/ovtest/alexnet_places365.caffemodel)";

        // Load the network
        cv::dnn::Net alexnetNet = cv::dnn::readNetFromCaffe(alexnetModelConfiguration, alexnetModelWeights);
        alexnetNet.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
        alexnetNet.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);

        std::string googlenetModelConfiguration = R"(/build/uk/source/ovtest/deploy_googlenet_places365.prototxt)";
        std::string googlenetModelWeights = R"(/build/uk/source/ovtest/googlenet_places365.caffemodel)";

        // Load the network
        cv::dnn::Net googlenetNet = cv::dnn::readNetFromCaffe(googlenetModelConfiguration, googlenetModelWeights);
        googlenetNet.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
        googlenetNet.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);

        std::string resnet152ModelConfiguration = R"(/build/uk/source/ovtest/deploy_resnet152_places365.prototxt)";
        std::string resnet152ModelWeights = R"(/build/uk/source/ovtest/resnet152_places365.caffemodel)";

        // Load the network
        cv::dnn::Net resnet152Net = cv::dnn::readNetFromCaffe(resnet152ModelConfiguration, resnet152ModelWeights);
        resnet152Net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
        resnet152Net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);

        std::string vgg16ModelConfiguration = R"(/build/uk/source/ovtest/deploy_vgg16_places365.prototxt)";
        std::string vgg16ModelWeights = R"(/build/uk/source/ovtest/vgg16_places365.caffemodel)";

        // Load the network
        cv::dnn::Net vgg16Net = cv::dnn::readNetFromCaffe(vgg16ModelConfiguration, vgg16ModelWeights);
        vgg16Net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
        vgg16Net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);

        std::string inputFile = R"(/build/uk/source/ovtest/Beach.png)";

        cv::Mat image = cv::imread(inputFile, cv::IMREAD_UNCHANGED);

        cv::Mat blob227 =
            cv::dnn::blobFromImage(image, 1.0, cv::Size(227, 227), cv::Scalar(103.94, 116.78, 123.68), true, false);
        cv::Mat blob224 =
            cv::dnn::blobFromImage(image, 1.0, cv::Size(224, 224), cv::Scalar(103.94, 116.78, 123.68), true, false);

        std::vector<cv::Mat> ret;
        alexnetNet.setInput(blob227);
        alexnetNet.forward(ret);
        std::cout << ret.size() << "  " << ret[0].rows << "  " << ret[0].cols << std::endl;

        googlenetNet.setInput(blob227);
        googlenetNet.forward(ret);
        std::cout << ret.size() << "  " << ret[0].rows << "  " << ret[0].cols << std::endl;

        resnet152Net.setInput(blob224);
        resnet152Net.forward(ret);
        std::cout << ret.size() << "  " << ret[0].rows << "  " << ret[0].cols << std::endl;

        vgg16Net.setInput(blob224);
        vgg16Net.forward(ret);
        std::cout << ret.size() << "  " << ret[0].rows << "  " << ret[0].cols << std::endl;

Error message:

OpenCV(4.8.0) Error: Requested object was not found (Required argument "operation" not found into dictionary) in get, file /build/uk/source/4.8.0_trial/source/lib/modules/dnn/include/opencv2/dnn/dnn.inl.hpp, line 350
[DEBUG:0@3.570] global system.cpp:2881 restoreFPDenormalsState core: restore FP mxcsr flags = 0x00001fa0
ERROR: caught an exception

I used the following files for the nets:

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)
@ukoehler ukoehler added the bug label Jul 21, 2023
@asmorkalov asmorkalov added category: dnn needs investigation Collect and attach more details (build flags, stacktraces, input dumps, etc) labels Jul 25, 2023
@zihaomu zihaomu self-assigned this Aug 10, 2023
@zihaomu
Copy link
Member

zihaomu commented Aug 12, 2023

Hi @ukoehler, update: test with MacOS 12.1, intel i9 and it works well, compier is XCode. Will test it on my Ubuntu later.

@ukoehler
Copy link
Author

Did you test release or debug?

@zihaomu
Copy link
Member

zihaomu commented Aug 14, 2023

Did you test release or debug?

release

@ukoehler
Copy link
Author

Your are not testing the problem: According to the documentation cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_VERBOSE); cannot be used in release mode. It is not documented what will happen if you use it anyway.

You have to build a debug version to see the effect.

@zihaomu
Copy link
Member

zihaomu commented Aug 15, 2023

@ukoehler. Thanks for your feedback. I'm working on it.

@zihaomu zihaomu linked a pull request Aug 15, 2023 that will close this issue
6 tasks
@opencv-alalek opencv-alalek added this to the 4.9.0 milestone Aug 15, 2023
@opencv-alalek opencv-alalek removed the needs investigation Collect and attach more details (build flags, stacktraces, input dumps, etc) label Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants