This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Onnx Fix 6 MaskRCNN models #20178
Merged
Merged
Onnx Fix 6 MaskRCNN models #20178
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,8 +199,6 @@ def obj_detection_test_images(tmpdir_factory): | |
tmpdir = tmpdir_factory.mktemp("obj_det_data") | ||
from urllib.parse import urlparse | ||
test_image_urls = [ | ||
'https://github.com/apache/incubator-mxnet-ci/raw/master/test-data/images/car.jpg', | ||
'https://github.com/apache/incubator-mxnet-ci/raw/master/test-data/images/duck.jpg', | ||
'https://github.com/apache/incubator-mxnet-ci/raw/master/test-data/images/fieldhockey.jpg', | ||
'https://github.com/apache/incubator-mxnet-ci/raw/master/test-data/images/flower.jpg', | ||
'https://github.com/apache/incubator-mxnet-ci/raw/master/test-data/images/runners.jpg', | ||
|
@@ -240,14 +238,20 @@ def obj_detection_test_images(tmpdir_factory): | |
'faster_rcnn_resnet101_v1d_coco', | ||
'yolo3_darknet53_coco', | ||
'yolo3_mobilenet1.0_coco', | ||
'mask_rcnn_resnet18_v1b_coco', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By adding the mask_rcnn under obj_detection tests, we are not testing the segmentation part? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the mask is a little hard to test numerically since they can be different across mxnet and onnxruntime |
||
'mask_rcnn_fpn_resnet18_v1b_coco', | ||
'mask_rcnn_resnet50_v1b_coco', | ||
'mask_rcnn_fpn_resnet50_v1b_coco', | ||
'mask_rcnn_resnet101_v1d_coco', | ||
'mask_rcnn_fpn_resnet101_v1d_coco', | ||
]) | ||
def test_obj_detection_model_inference_onnxruntime(tmp_path, model, obj_detection_test_images): | ||
def assert_obj_detetion_result(mx_ids, mx_scores, mx_boxes, | ||
onnx_ids, onnx_scores, onnx_boxes, | ||
score_thresh=0.6, score_tol=1e-4): | ||
def assert_bbox(mx_boxe, onnx_boxe, box_tol=1e-2): | ||
def assert_scalar(a, b, tol=box_tol): | ||
return np.abs(a-b) <= tol | ||
score_thresh=0.6, score_tol=0.0001, box_tol=0.01): | ||
def assert_bbox(mx_boxe, onnx_boxe): | ||
def assert_scalar(a, b): | ||
return np.abs(a-b) <= box_tol | ||
return assert_scalar(mx_boxe[0], onnx_boxe[0]) and assert_scalar(mx_boxe[1], onnx_boxe[1]) \ | ||
and assert_scalar(mx_boxe[2], onnx_boxe[2]) and assert_scalar(mx_boxe[3], onnx_boxe[3]) | ||
|
||
|
@@ -256,7 +260,6 @@ def assert_scalar(a, b, tol=box_tol): | |
onnx_id = onnx_ids[i][0] | ||
onnx_score = onnx_scores[i][0] | ||
onnx_boxe = onnx_boxes[i] | ||
|
||
if onnx_score < score_thresh: | ||
break | ||
for j in range(len(mx_ids)): | ||
|
@@ -267,18 +270,16 @@ def assert_scalar(a, b, tol=box_tol): | |
if onnx_score < mx_score - score_tol: | ||
continue | ||
if onnx_score > mx_score + score_tol: | ||
return False | ||
assert found_match, 'match not found' | ||
# check id | ||
if onnx_id != mx_id: | ||
continue | ||
# check bounding box | ||
if assert_bbox(mx_boxe, onnx_boxe): | ||
found_match = True | ||
break | ||
if not found_match: | ||
return False | ||
assert found_match, 'match not found' | ||
found_match = False | ||
return True | ||
|
||
def normalize_image(imgfile): | ||
img = mx.image.imread(imgfile) | ||
|
@@ -298,18 +299,26 @@ def normalize_image(imgfile): | |
|
||
for img in obj_detection_test_images: | ||
img_data = normalize_image(img) | ||
mx_class_ids, mx_scores, mx_boxes = M.predict(img_data) | ||
if model.startswith('mask_rcnn'): | ||
mx_class_ids, mx_scores, mx_boxes, _ = M.predict(img_data) | ||
else: | ||
mx_class_ids, mx_scores, mx_boxes = M.predict(img_data) | ||
# center_net_resnet models have different output format | ||
if 'center_net_resnet' in model: | ||
onnx_scores, onnx_class_ids, onnx_boxes = session.run([], {input_name: img_data.asnumpy()}) | ||
assert_almost_equal(mx_class_ids, onnx_class_ids) | ||
assert_almost_equal(mx_scores, onnx_scores) | ||
assert_almost_equal(mx_boxes, onnx_boxes) | ||
else: | ||
onnx_class_ids, onnx_scores, onnx_boxes = session.run([], {input_name: img_data.asnumpy()}) | ||
if not assert_obj_detetion_result(mx_class_ids[0], mx_scores[0], mx_boxes[0], \ | ||
onnx_class_ids[0], onnx_scores[0], onnx_boxes[0]): | ||
raise AssertionError("Assertion error on model: " + model) | ||
if model.startswith('mask_rcnn'): | ||
onnx_class_ids, onnx_scores, onnx_boxes, _ = session.run([], {input_name: img_data.asnumpy()}) | ||
assert_obj_detetion_result(mx_class_ids[0], mx_scores[0], mx_boxes[0], | ||
onnx_class_ids[0], onnx_scores[0], onnx_boxes[0], | ||
score_thresh=0.8, score_tol=0.05, box_tol=15) | ||
else: | ||
onnx_class_ids, onnx_scores, onnx_boxes = session.run([], {input_name: img_data.asnumpy()}) | ||
assert_obj_detetion_result(mx_class_ids[0], mx_scores[0], mx_boxes[0], | ||
onnx_class_ids[0], onnx_scores[0], onnx_boxes[0]) | ||
|
||
finally: | ||
shutil.rmtree(tmp_path) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we remove the images here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those two images would fail the maskrcnn models. It's not like maskrcnn models do not work on them, but they would output slightly different boxes than mxnet