Hi All,
I trained a model in Python. But i want to use the model by C++.
different result dnn in python and C++.
someone could help? thanks
model file https://github.com/shawnlee103/mytest/raw/master/my_model.pb
platform windows7 64 python 3.6 opencv 3.3.0.10
model = tf_model_path
net = cv2.dnn.readNetFromTensorflow(model)
x_myTest_list=[]
for filename in glob.iglob("D:\\test\\*.bmp", recursive=True):
input_img = cv2.imread(filename, cv2.IMREAD_GRAYSCALE)
cv2.imshow("input_img", input_img)
cv2.waitKey(1)
x_myTest_list.append(input_img)
for img in x_myTest_list:
img_input = cv2.dnn.blobFromImage(img, 0.00390625,(80,120))
#print(img_input.shape)
net.setInput(img_input, "conv2d_1_input")
prob = net.forward("dense_2/Softmax")
print(prob)
output:
[[ 9.99999642e-01 3.71539727e-07]]
[[ 9.99998093e-01 1.88101569e-06]]
[[ 9.99998927e-01 1.06129596e-06]].......
platform same (windows7 64 ), msvc2015, opencv 3.3.1
for (int i = 0; i < imageFiles.size(); i++)
{
Mat img = imread(imageFiles[i], CV_LOAD_IMAGE_GRAYSCALE);
Mat inputBlob = dnn::blobFromImage(img, 0.00390625f, Size(80, 120), Scalar(), false);
Mat prob;
try {
CV_TRACE_REGION("forward");
net.setInput(inputBlob, "conv2d_1_input");
prob = net.forward("dense_2/Softmax");output
PrintfMat(prob, "prob");
}
catch (cv::Exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
system("pause");
}
}
output:
Net Outputs(1):
dense_2/Softmax
0.53188 0.46812
0.54745 0.45255
0.57105 0.42895...