I am experiencing an access violation exception when using OpenCv::dnn::Net forward function.
std::string m_pathCaffeModel;
std::string m_pathConfig;
m_pathCaffeModel = "model.caffemodel";
m_pathConfig = "model.prototxt";
cv::dnn::Net m_net;
m_net = cv::dnn::readNetFromCaffe(m_pathConfig, m_pathCaffeModel);
cv::Mat blob;
cv::dnn::blobFromImage(resized, blob, 1.0, cv::Size(), cv::Scalar(), false, false, CV_32F);
m_net.setInput(blob);
m_net.forward();
When I call net.forward() I get the following error:
Exception thrown at 0x00007FFD2C1B12DE (vcruntime140.dll) in my_exe.exe: 0xC0000005: Access violation reading location 0x000001C521201000
I checked the input image (called "resized" in the code) printing and that looks good. Its dimensions and data also look correct.
To me the blob looks suspicious, because it has -1 rows and -1 columns. I don't know if this is a problem.
The model accepts 40x40 3-channels images.
Does anyone have a suggestion about what is the cause of the problem and how to fix it?
Using C++ and OpenCV::dnn::Net, it is necessary to define some further settings:
net.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
(the above for CPU inference)
with these two lines before net.forward() the error disappears and it works.
User contributions licensed under CC BY-SA 3.0