DNN use of neural network foward() to several images

asked 2016-04-27 17:16:02 -0600

Paulo gravatar image

Hi, i used the tutorial in the link https://github.com/Itseez/opencv_cont... then i changed the code and wrote a for loop to use the cv::dnn::net::foward() to same image different times and an error in output has occurred.

cv::dnn::Net net;
importer->populateNet(net);
dnn::Blob inputBlob = dnn::Blob(img);
net.setBlob(".data", inputBlob);

for(size_t i = 0; i <5; i++)
{
        net.forward();
        dnn::Blob prob = net.getBlob("prob");   //gather output of "prob" layer
    int classId;
    double classProb;
    getMaxClass(prob, &classId, &classProb);//find the best class
    std::vector<String> classNames = readClassNames();
    for (size_t i = 0; i < classNames.size(); i++)
    {
        cout << classNames[i]<<endl;
    }

    std::cout << "Best class: #" << classId << " '" << classNames.at(classId) << "'" << std::endl;
    std::cout << "Probability: " << classProb * 100 << "%" << std::endl;
}

The problem is that i gave to the neural network inputBlob of the same image in a for loop and the predictions are different. Somebody can help? Have another question, how can i give several input image blobs to a neural network in a for loop to predict different images?

edit retag flag offensive close merge delete

Comments

Hi, did you solve the problem?, I see a code here: http://stackoverflow.com/questions/38...

I have a question, the result of your predictions are coherent?, I have a binary classifier and always throw classId=0, and classProb=100%. Did you have a similar problem?

Thanks

sisi004 gravatar imagesisi004 ( 2016-09-04 18:02:06 -0600 )edit