I’m feeding the same model with the same input (same image that pass by the same operations) parameters in C++ and Python, but they are giving me different outputs. I know the Python outputs is what I expect as an output. But why C++ is having this behavior?
My C++ code:
...
cv::Mat img = imread("debugg.bmp");
cv::dnn::Image2BlobParams params;
params.scalefactor = 1.0;
params.size = cv::Size2i::Size_(30, 30);
params.mean = 0.0;
params.ddepth = CV_32F;
params.datalayout = cv::dnn::DNN_LAYOUT_NHWC;
params.paddingmode = cv::dnn::DNN_PMODE_NULL;
params.swapRB = false;
cv::Mat imgFloat;
img.convertTo(imgFloat, CV_32F);
imgFloat /= 255.0f;
cv::Mat blobPB;
cv::dnn::blobFromImageWithParams(imgFloat, blobPB, params);
modelPB.setInput(blobPB);
cv::Mat outputPB = modelPB.forward();
Python code:
...
params = cv2.dnn.Image2BlobParams()
params.scalefactor = 1.0
params.size = (30, 30)
params.mean = 0.0
params.ddepth = cv2.CV_32F
params.datalayout = cv2.dnn.DNN_LAYOUT_NHWC
params.paddingmode = cv2.dnn.DNN_PMODE_NULL
img = cv2.imread("debugg.bmp")
img_float = img.astype(np.float32)
img_float /= 255
blobPB = cv2.dnn.blobFromImageWithParams(img_float, params)
modelopenCV.setInput(blobPB)
output = modelopenCV.forward()