the outputs of net.forward() are different by opencv4.0.0 win-pack and build-from-source

asked 2019-02-11 06:48:07 -0600

lunasdejavu gravatar image

updated 2019-02-12 18:45:34 -0600

My environment is windows 7 x64 tensorflow 1.12 GPU:GTX1060 visual studio 2015 and the dataset has only 1 class. I trained a faster_rcnn_inception_v2_coco model by tensorflow-object detection api, then I did the inference by the C++ code like:

string weights = "C:\\tf_od_api\\models\\faster_rcnn_inception_v2_coco\\pb\\frozen_inference_graph.pb";
string prototxt = "C:\\tf_od_api\\models\\faster_rcnn_inception_v2_coco\\pb\\graph.pbtxt";
cv::dnn::Net net = cv::dnn::readNetFromTensorflow(weights, prototxt);
cv::Mat frame = cv::imread("C:\\hsir\\build\\bin\\test\\test-c1-1.bmp");
cv::Mat blob = cv::dnn::blobFromImage(frame, 1, cv::Size(inWidth, inHeight), false, true);
net.setInput(blob);
cv::Mat outPut = net.forward();
cv::Mat detectionMat = cv::Mat(outPut.size[2], outPut.size[3], CV_32F, outPut.ptr<float>());

it works fine by my code with opencv 4.0.0 and 4.0.1 installed by win-pack, but I tried to put it in a project of my team which seems to use customized opencv from 4.0.0 which was build from source, then the detectionMat is totally wrong. I traced the bug and just copied the same code into a function of the project, but the result was still wrong. There was no error or warning shows up and nothing wrong with reading the model, image and forward(); The correct result should be only one object detected with confidence 1.0 and the others with confidence 0.0. The wrong result has 100 objects detected with 0.5~0.99 confidences but none of them close to the real object.

the graph.pbtxt is here frozen_inference_graph.pb is here image is here

Does anyone know what is wrong with the code?the output image

edit retag flag offensive close merge delete

Comments

@lunasdejavu, the following thing is unclear but I tried to put it in a project of my team which seems to use customized opencv from 4.0.0 which was build from source. Your code sample also incomplete. Nobody can reproduce it unless inWidth and inHeight are specified. Please try to use OpenCV's object detection sample at first, provide command line arguments which were used and received results.

dkurt gravatar imagedkurt ( 2019-02-12 01:40:19 -0600 )edit

inWidth= inHeight=1024 Here is the thing: The code works fine under visual studio 2015 x64 release with opencv 4.0.0 installed by win-pack but totally wrong by the vs 2015 complier with opencv 4.0.0 built from the source. there is no need for the sample since they are just simple cv::dnn functions. the output of net.forward() is totally wrong already.

lunasdejavu gravatar imagelunasdejavu ( 2019-02-12 02:01:49 -0600 )edit

I just checked OpenCVConfig.cmake,

- OpenCV_VERSION_STATUS : Development status of this build: ""

so the version status is the same.

lunasdejavu gravatar imagelunasdejavu ( 2019-02-12 03:03:04 -0600 )edit