Skip to content

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

@ukoehler

Description

@ukoehler

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)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions