Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

(DNN) different results between version 3.3.0 and 3.3.1

System information (version)

OpenCV => 3.3.0/3.3.1

Operating System / Platform => Windows 10 64 Bit

Compiler => Visual Studio 2015

Detailed description

I have a network that works fine in Opencv 3.3.0, but after updating my opencv to the version 3.3.1 I'm getting wrong results with the same code. What I already tried:

*Compile on Linux -> I got the same wrong results

*Compile on windows with Mingw -> I got the same wrong results

*Compile on windows with Visual Studio 14 x32 -> I got the same wrong results

*Compile the master brach of opencv on windows with Visual Studio 14 x32 -> I got the same wrong results

Complementar tests: I used the "tensorflow_inception_graph.pb" network, with this network I got the same results in version 3.3.0 and 3.3.1, I do not know if it is a correct predictions. Using the caffe model network from the opencv examples worked as well with correct prediction for both versions.

Maybe my problem is my network, but why my network works on opencv 3.3.0 and dont work on 3.3.1?

Steps to reproduce

NetworkInput: 1x1x28x92 (grayscale image)

Normalization: 0..1

The same code is used in opencv 3.3.0 and 3.3.1

my network you can find here

#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/core/utils/trace.hpp>
//using namespace cvtest;
using namespace cv;
using namespace cv::dnn;


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

static 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;
}
int main()
{

    //CV_TRACE_FUNCTION();
    String modelBin = "model_final.pb";
    String imageFile = "airplane.jpg";
    Net net = dnn::readNetFromTensorflow(modelBin);
    if (net.empty())
    {
        std::cerr << "Can't load network by using the following files: " << std::endl;
        std::cerr << "Tensorflow model: " << modelBin << std::endl;
        exit(-1);
    }

    Mat img = imread(imageFile,0);
    if (img.empty())
    {
        std::cerr << "Can't read image from the file: " << imageFile << std::endl;
        exit(-1);
    }
    Mat resized;
    resize(img, resized, Size(92, 28));
    float escala=1.0/255.0;
    Mat inputBlob = blobFromImage(resized,escala, Size(92, 28),Scalar(0,0,0),false);   //Convert Mat to batch of images
    std::cout << inputBlob.size << std::endl;
    Mat prob;

    cv::TickMeter t;
    for (int i = 0; i < 100; i++)
    {
        //CV_TRACE_REGION("forward");
        t.start();
        net.setInput(inputBlob, "conv2d_1_input");        //set the network input
        prob = net.forward("activation_4/Softmax");                          //compute output
        //std::cout << prob << std::endl;
        t.stop();
    }
    int classId;
    double classProb;
    getMaxClass(prob, &classId, &classProb);//find the best class

    std::cout << prob<< std::endl;
    std::cout << "Best class: #" << classId << std::endl;
    std::cout << "Probability: " << classProb * 100 << "%" << std::endl;
    std::cout << "Time: " << (double)t.getTimeMilli() / t.getCounter() << " ms (average from " << t.getCounter() << " iterations)" << std::endl;

    namedWindow("DEBUG", WINDOW_AUTOSIZE);   // Create a window for display.
    imshow("DEBUG", img);                   // Show our image inside it.
    waitKey(0);
    return 0;
} //main*/

Using the file .pbtxt as argument to load the network could help me? how is the correct way to generate this file?