Using two dnn networks causes crash [closed]
Hi I wanna to using two yolo networks in my program (an yolo3-tiny and an yolov3-spp), but when I call net.forward function for the second network, I'm got following exception :
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(4.0.0-pre) /home/pouya/Develop/opecv4/opencv/modules/dnn/src/dnn.cpp:1149: error: (-204:Requested object was not found) Layer with requested id=-1 not found in function 'getLayerData'
there is my code :
bool Detector::postprocesstiny(const std::vector<cv::Mat>& outs)
{
for (size_t i = 0; i < outs.size(); ++i)
{
float* data = (float*)outs[i].data;
for (int j = 0; j < outs[i].rows; ++j, data += outs[i].cols)
{
cv::Mat scores = outs[i].row(j).colRange(5, outs[i].cols);
cv::Point classIdPoint;
double confidence;
minMaxLoc(scores, 0, &confidence, 0, &classIdPoint);
if (classIdPoint.x==2 && confidence > 0.5)
return true ;
}
}
return false ;
}
std::vector<cv::String> Detector::getOutputsNames(const cv::dnn::Net& net)
{
static std::vector<cv::String> names;
if (names.empty())
{
std::vector<int> outLayers = net.getUnconnectedOutLayers();
std::vector<cv::String> layersNames = net.getLayerNames();
names.resize(outLayers.size());
for (size_t i = 0; i < outLayers.size(); ++i)
names[i] = layersNames[outLayers[i] - 1];
}
return names;
}
bool Detector::isThereAnyCar(cv::Mat image) {
cv::Mat inputBlob = cv::dnn::blobFromImage(image, 1 / 255.F , cv::Size(416, 416), cv::Scalar(), true, false);
net_tiny.setInput(inputBlob);
std::vector<cv::Mat> outs;
net_tiny.forward(outs, getOutputsNames(net_tiny));
return postprocesstiny(outs);
}
cv::dnn::Net net = cv::dnn::readNetFromDarknet(modelConfiguration, modelBinary);
cv::dnn::Net net_tiny = cv::dnn::readNetFromDarknet(modelConfigurationTiny, modelBinaryTiny);
cv::Mat frame;
cv::VideoCapture cap(source);
cap >> frame;
if (isThereAnyCar(frame)) {
cv::Mat inputBlob = cv::dnn::blobFromImage(frame, 1 / 255.F , cv::Size(416, 416), cv::Scalar(), true, false);
net.setInput(inputBlob);
std::vector<cv::Mat> outs;
std::vector<DetectionResult> detection_results;
net.forward(outs, getOutputsNames(net)); //This line causes error
}
and when I comment one of the networks, it runs without any problem. Is there any solution for this problem?
There is the configuration of this network : https://github.com/pjreddie/darknet/b...
so, the problem is NOT running 2 networks, but that there is something unsupported in the (new) ssp model, right ?
(if you thing it has to do with 2 networks, the, ofc. we need to see your code !)
No I can run the ssp model without any problem, but when I want to run two networks to gather I get this error
thank you, just added :) the last line causes error but when I comment if (isThereAnyCar(frame)) or net.forward(outs, getOutputsNames(net)) there is no error
i can only guess now, but the tiny-yolo is v2, and the ssp one v3, right ? imho, you cannot reuse the
outs
Mat vector for both of them, and they will have different outnames, too.i also guess, if you change the order, you get an error in the other network ;)