Issue 1:
System information (version)

OpenCV => 3.4.1

Operating System / Platform => Windows 64 Bit

Compiler => Visual Studio 2017

Detailed description

So I'm training an Inception resnet model on tensorflow, and I get a .ckpt/.meta files. From this I generate a .pb frozen graph. I call this .pb file in C++ for inference.

But the opencv module comes up with the error as

OpenCV(3.4.1) Error: Unspecified error (Unknown layer type OneShotIterator in op OneShotIterator) in cv::dnn::experimental_dnn_v4

Why does Opencv not recognize my pipeline layer? The same thing happened when the code initially had a FIFOQueue as pipeline for data. Is there someway I can remove these layers?

I looked at the layers in Opencv 4.1.0 and it doesn't have a one shot iterator, so please help me out!

Steps to reproduce

One thing I'm not so sure is if I can use the sample C++ file for inception model to call my graph which is not inception but inception resnet? Does it make any difference? attached code below

// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.

// Copyright (C) 2016, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.

/*
Sample of using OpenCV dnn module with Tensorflow Inception model.
*/

#include <stdafx.h>
using namespace cv;
using namespace cv::dnn;

#include <fstream>
#include <iostream>
#include <cstdlib>
using namespace std;

const String keys =
"{help h || Sample app for loading Inception TensorFlow model. "
"The model and class names list can be downloaded here: "
"https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip }"
"{model m |tensorflow_inception_graph.pb| path to TensorFlow .pb model file }"
"{image i || path to image file }"
"{i_blob | input | input blob name) }"
"{o_blob | softmax2 | output blob name) }"
"{c_names c | imagenet_comp_graph_label_strings.txt | path to file with classnames for class id }"
"{result r || path to save output blob (optional, binary format, NCHW order) }"
;

void getMaxClass(const Mat &probBlob, int *classId, double *classProb);
std::vector<String> readClassNames(const char *filename);

int main(int argc, char **argv)
{
cv::CommandLineParser parser(argc, argv, keys);

if (parser.has("help"))
{
parser.printMessage();
return 0;
}

String modelFile = "frozen_mode_final.pb";
String imageFile = "Lena.jpg";
String inBlobName = "input";
String outBlobName = "outputs_";

if (!parser.check())
{
parser.printErrors();
return 0;
}

String classNamesFile = "imagenet_comp_graph_label_strings.txt";
String resultFile = "output.txt";

//! [Initialize network]
dnn::Net net = readNetFromTensorflow(modelFile);
//! [Initialize network]

if (net.empty())
{
std::cerr << "Can't load network by using the mode file: " << std::endl;
std::cerr << modelFile << std::endl;
exit(-1);
}

//! [Prepare blob]
Mat img = imread(imageFile);
if (img.empty())
{
std::cerr << "Can't read image from the file: " << imageFile << std::endl;
exit(-1);
}

Mat inputBlob = blobFromImage(img, 1.0f, Size(299, 299), Scalar(), true, false); //Convert Mat to batch of images
//! [Prepare blob]
inputBlob -= 117.0;
//! [Set input blob]
net.setInput(inputBlob, inBlobName); //set the network input
//! [Set input blob]

cv::TickMeter tm;
tm.start();

//! [Make forward pass]
Mat result = net.forward(outBlobName); //compute output
//! [Make forward pass]

tm.stop();

if (!resultFile.empty()) {
CV_Assert(result.isContinuous());

ofstream fout(resultFile.c_str(), ios::out | ios::binary);
fout.write((char*)result.data, result.total() * sizeof(float));
fout.close();
}

std::cout << "Output blob shape " << result.size[0] << " x " << result.size[1] << " x " << result.size[2] << " x " << result.size[3] << std::endl;
std::cout << "Inference time, ms: " << tm.getTimeMilli() << std::endl;

if (!classNamesFile.empty()) {
std::vector<String> classNames = readClassNames(classNamesFile.c_str());

int classId;
double classProb;
getMaxClass(result, &classId, &classProb);//find the best class

//! [Print results]
std::cout << "Best class: #" << classId << " '" << classNames.at(classId) << "'" << std::endl;
std::cout << "Probability: " << classProb * 100 << "%" << std::endl;
}
return 0;
} //main

/* Find best class for the blob (i. e. class with maximal probability) */
void getMaxClass(const Mat &probBlob, int *classId, double *classProb)
{
Mat probMat = probBlob.reshape(1, 1); //reshape the blob to 1x1000 matrix
Point classNumber;

minMaxLoc(probMat, NULL, classProb, NULL, &classNumber);
*classId = classNumber.x;
}

std::vector<String> readClassNames(const char *filename)
{
std::vector<String> classNames;

std::ifstream fp(filename);
if (!fp.is_open())
{
std::cerr << "File with classes labels not found: " << filename << std::endl;
exit(-1);
}

std::string name;
while (!fp.eof())
{
std::getline(fp, name);
if (name.length())
classNames.push_back(name);
}

fp.close();
return classNames;
}```

Issue 2:
System information (version)

OpenCV => :4.1.0:

Operating System / Platform => :ubuntu 18.04 LTS:

Compiler => : clang-7:

Detailed description

An issue was discovered in opencv 4.1.0, there is an out of bounds read/write in Function HaarEvaluator::OptFeature::calc in cascadedetect.hpp, which leads to denial of service.

src

#define CALC_SUM_OFS_(p0, p1, p2, p3, ptr) \
((ptr)[p0] - (ptr)[p1] - (ptr)[p2] + (ptr)[p3])

#define CALC_SUM_OFS(rect, ptr) CALC_SUM_OFS_((rect)[0], (rect)[1], (rect)[2], (rect)[3], ptr)

debug

In file: /home/pwd/SofterWare/opencv-4.1.0/modules/objdetect/src/cascadedetect.hpp
390 ofs[2][0] = ofs[2][1] = ofs[2][2] = ofs[2][3] = 0;
391 }
392
393 inline float HaarEvaluator::OptFeature :: calc( const int* ptr ) const
394 {
► 395 float ret = weight[0] * CALC_SUM_OFS(ofs[0], ptr) +
396 weight[1] * CALC_SUM_OFS(ofs[1], ptr);
397
398 if( weight[2] != 0.0f )
399 ret += weight[2] * CALC_SUM_OFS(ofs[2], ptr);
400
─────────────────────────────────────────────────────────────────────────────────────────────────────[ STACK ]─────────────────────────────────────────────────────────────────────────────────────────────────────
00:0000│ rbp rsp 0x7fffc7ffe2b0 —▸ 0x7fffc7ffe2e0 —▸ 0x7fffc7ffe3c0 —▸ 0x7fffc7ffe470 —▸ 0x7fffc7ffe5b0 ◂— ...
01:0008│ 0x7fffc7ffe2b8 —▸ 0x7ffff5e3c218 ◂— mov rax, qword ptr [rbp - 0x18]
02:0010│ 0x7fffc7ffe2c0 —▸ 0x7fffc7ffe2e0 —▸ 0x7fffc7ffe3c0 —▸ 0x7fffc7ffe470 —▸ 0x7fffc7ffe5b0 ◂— ...
03:0018│ 0x7fffc7ffe2c8 —▸ 0x7fffcc000ce0 —▸ 0x7ffff60d0e08 —▸ 0x7ffff5e25d30 (cv::HaarEvaluator::~HaarEvaluator()) ◂— push rbp
04:0020│ 0x7fffc7ffe2d0 ◂— 0x7d00000000
05:0028│ 0x7fffc7ffe2d8 —▸ 0x7fffcc000ce0 —▸ 0x7ffff60d0e08 —▸ 0x7ffff5e25d30 (cv::HaarEvaluator::~HaarEvaluator()) ◂— push rbp
06:0030│ 0x7fffc7ffe2e0 —▸ 0x7fffc7ffe3c0 —▸ 0x7fffc7ffe470 —▸ 0x7fffc7ffe5b0 —▸ 0x7fffc7ffe650 ◂— ...
07:0038│ 0x7fffc7ffe2e8 —▸ 0x7ffff5e2bdad ◂— movss dword ptr [rbp - 0xcc], xmm0
───────────────────────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]───────────────────────────────────────────────────────────────────────────────────────────────────
► f 0 7ffff5e3c24c
f 1 7ffff5e3c218
f 2 7ffff5e2bdad
f 3 7ffff5e2ba90
f 4 7ffff5e3bd74
f 5 7fffef87dc59
f 6 7fffef87ea3b cv::ParallelJob::execute(bool)+603
f 7 7fffef87e21a cv::WorkerThread::thread_body()+890
f 8 7fffef880e05 cv::WorkerThread::thread_loop_wrapper(void*)+21
f 9 7fffee3d46db start_thread+219
Program received signal SIGSEGV (fault address 0x7ffdd53a6cdc)
pwndbg> p ofs
$9 = {{-2147481185, -2147481182, -2147479073, -2147479070}, {2470, 2471, 4582, 4583}, {0, 0, 0, 0}}

Steps to reproduce

classifier /work/funcs/appname.bmp poc

poc1.tar.gz