OpenCV forward() inference size is different between python and c++

asked 2020-03-30 09:08:18 -0600

dernanmi34 gravatar image

updated 2020-03-30 10:15:02 -0600

i have trained a classification model, when loaded using OpenCV readNetFromTensorflow

In python using net.forward() it gives me an output of size 1 X nbrOfClasses which is correct

In C++ using the same parameters it gives me the size of nbrOfClasses X 64 ? i dont understand what is this output ( "this 64 " )and why its not the same as in python ,

ps, i am using opencv 3.4.2 in both C++ and python.

Any ideas what's going on ?

my model.pbtxt is here and the model.pb is here

my code in c++

    String model = "model.pb";
String config = "model.pbtxt";
dnn::Net net = cv::dnn::readNetFromTensorflow(model, config);

string imgFullPath = "anyImage.jpg";
Mat img = cv::imread(imgFullPath, IMREAD_GRAYSCALE);
Mat blob = blobFromImages(img, 1.0, Size(64, 64), Scalar(0, 0, 0), true, true);
net.setInput(blob);
Mat forward = net.forward();
cout << "forward size : " << forward.size() << endl;

my code in python :

    net = cv.dnn.readNetFromTensorflow(modelWeights, textGraph); 
pathImg="anyImage.jpg"
frame=cv.imread(pathImg, cv.IMREAD_GRAYSCALE)

blob = cv.dnn.blobFromImage(frame,1.0,(64,64),[0,0,0],True,True)
net.setInput(blob)
outputBlob = net.forward()
print(outputBlob.shape)
edit retag flag offensive close merge delete

Comments

show resp. piece of code, please.

also, sample code

berak gravatar imageberak ( 2020-03-30 09:13:36 -0600 )edit

3.4.2

ugghhh that's old..

berak gravatar imageberak ( 2020-03-30 09:34:55 -0600 )edit

rather print out forward.size (w/o braces !) for the network output in c++

berak gravatar imageberak ( 2020-03-30 09:49:02 -0600 )edit

its following this sample code, but still the problem is the size of net.forward() which is confusing !!

dernanmi34 gravatar imagedernanmi34 ( 2020-03-30 09:49:53 -0600 )edit