Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.

OpenVINO R2 c++ example not working.

N__Harsha
Beginner
747 Views

Hi , I am trying to run this simple opencv dnn inference with openvino. I get this error. Can somebody help ?

The code I am using is below. The model is tensorflow object detection api, converted to openvino format. I am able to run inference in openvino style API and example code. But when I use opencv style API, I get this error. Error is for the line net.forward() I looked up on github, it points to below patch on github

Error:

OpenCV(4.1.1-openvino) Error: Assertion failed (inp.total()) in cv::dnn::dnn4_v20190621::Net::Impl::allocateLayers, file C:\jenkins\workspace\OpenCV\OpenVINO\build\opencv\modules\dnn\src\dnn.cpp, line 2182

Code on Github, where the assertion points to

void allocateLayers(const std::vector<LayerPin>& blobsToKeep_)
    {
        CV_TRACE_FUNCTION();

        MapIdToLayerData::iterator it;
        for (it = layers.begin(); it != layers.end(); it++)
            it->second.flag = 0;

        CV_Assert(!layers[0].outputBlobs.empty());
        ShapesVec inputShapes;
        for(int i = 0; i < layers[0].outputBlobs.size(); i++)
        {
            Mat& inp = layers[0].outputBlobs;
            CV_Assert(inp.total());
            if (preferableBackend == DNN_BACKEND_OPENCV &&
                preferableTarget == DNN_TARGET_OPENCL_FP16)

 

My actual Code

    std::string modelPath = "Models\\frozen_inference_graph.xml";
	std::string binPath = "Models\\frozen_inference_graph.bin";
	std::string imagePath = "09445904.jpg";
	std::string labelFilePath = "Models\\coco.names";

	// load the labels file
	std::vector<std::string> classes;
	std::ifstream ifs(labelFilePath.c_str());
	if (!ifs.is_open())
		CV_Error(Error::StsError, "File " + labelFilePath + " not found");
	string line;
	while (std::getline(ifs, line))
	{
		classes.push_back(line);
	}


	cv::Mat im = cv::imread(imagePath);
	cv::Mat blob;
	Net net = readNetFromModelOptimizer(modelPath, binPath);
	net.setPreferableBackend(DNN_BACKEND_INFERENCE_ENGINE);
	net.setPreferableTarget(DNN_TARGET_CPU);

	blobFromImage(im, blob, 1.0, Size(600, 600));

	// set the blob as input to the network and perform a forward-pass to
	// obtain our output classification
	net.setInput(blob, "image_tensor");
	auto detection = net.forward("detection_output");  //<- error on this line.
0 Kudos
1 Reply
Shubha_R_Intel
Employee
747 Views

Dear N, Harsha,

This is the OpenVino forum, where we support Inference Engine Core APi and also Model Optimizer. Kindly post your question to OpenCV Issues and you will get better help there.

Thanks,

Shubha

0 Kudos
Reply