[dnn] fix high level api for python#19484
[dnn] fix high level api for python#19484alalek merged 3 commits intoopencv:masterfrom UnaNancyOwen:fix_highlevelapi
Conversation
|
@UnaNancyOwen Thank you for contribution. Can you add simple tests to verify Python bindings functionality for exported classes are fixed? |
|
@VadimLevin Sorry, That could be difficult for me. I don't know how python / dnn-module testing in OpenCV. |
You can add a test to |
|
@VadimLevin I have written a test. Please check following. def test_textdetection_model_db(self):
img_path = self.find_dnn_file("dnn/text_det_test1.png")
weights = self.find_dnn_file("onnx/models/DB_TD500_resnet50.onnx", required=False)
ref = np.load(self.find_dnn_file("dnn/DB_TD500_resnet50_prob.npy"))
if weights is None:
raise unittest.SkipTest("Missing DNN test files (onnx/models/DB_TD500_resnet50.onnx). Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.")
frame = cv.imread(img_path)
model = cv.dnn_TextDetectionModel_DB(weights)
model.setInputScale(1.0 / 255.0)
model.setInputSize(736, 736)
model.setInputMean(122.67891434, 116.66876762, 104.00698793)
out = model.predict(frame)
normAssert(self, out, ref) |
That's my suggestion to use model from |
(I don't understand how it works, but) is it okay if the model is described in opencv_extra/testdata/dnn/download_models.py?
That's a good idea. I took that idea in test code. def test_textdetection_model_db(self):
img_path = self.find_dnn_file("dnn/text_det_test1.png")
weights = self.find_dnn_file("dnn/onnx/models/DB_TD500_resnet50.onnx", required=False)
if weights is None:
raise unittest.SkipTest("Missing DNN test files (onnx/models/DB_TD500_resnet50.onnx). Verify OPENCV_DNN_TEST_DATA_PATH configuration parameter.")
frame = cv.imread(img_path)
scale = 1.0 / 255.0
size = (736, 736)
mean = (122.67891434, 116.66876762, 104.00698793)
model = cv.dnn_TextDetectionModel_DB(weights)
model.setInputParams(scale, size, mean)
out = model.predict(frame)
net = cv.dnn.readNet(weights)
blob = cv.dnn.blobFromImage(frame, scale, size, mean)
net.setInput(blob)
ref = net.forward()
normAssert(self, out, ref) |
| model = cv.dnn_TextDetectionModel_DB(weights) | ||
| model.setInputParams(scale, size, mean) | ||
| out = model.predict(frame) |
There was a problem hiding this comment.
This code shows that patch in .hpp file is not necessary to pass this test (test doesn't fail without the patch).
Please update test code (it should fail before and pass after the patch).
There is strong recommendation to avoid accuracy checking in Python (and others) bindings tests. |
|
@alalek I will fix test to check type and shape of output. |
* [dnn] fix high level api for python * [dnn] add test_textdetection_model_db * [dnn] fix textdetection test only check type and shape
fix #19346
fix #19481
original opinion by @mikr. thanks! #19346 (comment)
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.