Ask Your Question

Rodrigo2019's profile - activity

2017-12-21 06:46:01 -0500 marked best answer (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 ...
(more)
2017-12-21 06:46:01 -0500 received badge  Scholar (source)
2017-12-21 06:45:41 -0500 commented answer (DNN) different results between version 3.3.0 and 3.3.1

@dkurt, thanks a lot, your modifications will help me a lot

2017-12-21 06:44:00 -0500 commented answer (DNN) different results between version 3.3.0 and 3.3.1

@dkurt, I tested what did you said. First I downloaded the last version of opencv-master and replaced with your files Te

2017-12-21 04:48:14 -0500 commented question (DNN) different results between version 3.3.0 and 3.3.1

I create my batchs doing something like this: im=cv2.imread("example.jpg",0) #It will load in grayscale im=im/255.0 #sc

2017-12-21 04:14:19 -0500 received badge  Enthusiast
2017-12-20 12:46:50 -0500 commented answer (DNN) different results between version 3.3.0 and 3.3.1

for sure, I will test it tomorrow morning and I post the results here

2017-12-20 12:45:43 -0500 commented question (DNN) different results between version 3.3.0 and 3.3.1

I create my batchs doing something like this: im=cv2.imread("example.jpg",0) #It will load in grayscale im=im/255.0 #sc

2017-12-19 10:28:50 -0500 answered a question (DNN) different results between version 3.3.0 and 3.3.1

Thank you so much Dkurt, I would never found this answer by myself. I will test as soon as possible, thank you

2017-12-15 06:14:15 -0500 asked a question (DNN) different results between version 3.3.0 and 3.3.1

(DNN) different results between version 3.3.0 and 3.3.1 System information (version) OpenCV => 3.3.0/3.3.1 Operatin

2017-11-13 08:53:54 -0500 answered a question (dnn/tensorflow) Very different results tf X dnn

here it is the problem: #9177

2017-11-09 11:01:43 -0500 asked a question (dnn/tensorflow) Very different results tf X dnn

(dnn/tensorflow) Very different results tf X dnn Hello, I created a keras model and converted to tensorflow, I had some