-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[FRONTEND][TFLITE] Add support for TFLite_Detection_PostProcess #4543
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
494f544
6378ef5
eeb611e
aa678cf
505e7f0
a7fc2a3
5f9cba6
7fca345
7e69839
5b7f549
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1353,6 +1353,51 @@ def test_forward_fully_connected(): | |
| _test_fully_connected([5, 1, 1, 150], [150, 100], [100]) | ||
|
|
||
|
|
||
| ####################################################################### | ||
| # Custom Operators | ||
| # ---------------- | ||
|
|
||
| def test_detection_postprocess(): | ||
| tf_model_file = tf_testing.get_workload_official( | ||
| "http://download.tensorflow.org/models/object_detection/" | ||
| "ssd_mobilenet_v2_quantized_300x300_coco_2019_01_03.tar.gz", | ||
|
Member
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. would you mind adding more models like ssd_mobilenetv1?
Contributor
Author
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 can do, but where would you like me to pull it from? I see that ssd mobilenet v1 without the post process op is hosted under "https://raw.githubusercontent.com/dmlc/web-data/master/tensorflow/models/", would it be possible to host the version with the post process op here as well?
Member
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. If possible, we'd like to pull the model from the related official website, for example https://www.tensorflow.org/lite/models/object_detection/overview for ssd mobilenet v1.
Contributor
Author
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. OK - I did see that model but weirdly it was as a .zip, not a tar as with most other hosted models. I'll see if I can open another PR to extend get_workload_official to zips and then will add the test.
Contributor
Author
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. The test looks non-trivial to add because quite a small difference in the convolutional part of the network can result in significant changes to the ordering of the output tensor (eg. we might see at different detection at the cut off threshold). I'm not sure what the best way is to proceed, do you have any thoughts?
Member
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. Alright, we could remove ssd mobilenet model because of this limitation, but we should still keep the unit testing of detection postprocess. After we resolve the limitation, we could add ssd mobilenet testing back. Morever, we could remove the atol=1 of test_qconv2d and so on. Because we could get the same result completely compared with the tflite. Does it make sense to you?
Contributor
Author
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. This test is a bit misleading because it doesn't actually run ssd mobilenet, it just test the postprocess op. I couldn't find a way to create the op using the tflite python API, so what I did instead was take a model that has it and then run it through the tflite converter but with the converter inputs set to the inputs of the postprocess op rather than the input to the network. This has the net effect of producing a single postprocess op, so this should already be a unit test (and it passes). I can add the end-to-end tests if/when we resolve the QNN accuracy issue. I'll open an RFC shortly to describe why rounding is a particularly significant in the case of this operator.
Member
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 if we could view the TOCO source code, maybe we could find how to construct detection_postprocess. Please refer our
Contributor
Author
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've written a discuss post here: 5528. 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. @mbaret How did you set converter input as inputs of postprocess op, when I do that it gives me error : The inputs to postprocess op >1 ('raw_outputs/box_encodings','raw_outputs/class_predictions') also anchors constant |
||
| "ssd_mobilenet_v2_quantized_300x300_coco_2019_01_03/tflite_graph.pb" | ||
| ) | ||
| converter = tf.lite.TFLiteConverter.from_frozen_graph( | ||
| tf_model_file, | ||
| input_arrays=["raw_outputs/box_encodings", "raw_outputs/class_predictions"], | ||
| output_arrays=[ | ||
| "TFLite_Detection_PostProcess", | ||
| "TFLite_Detection_PostProcess:1", | ||
| "TFLite_Detection_PostProcess:2", | ||
| "TFLite_Detection_PostProcess:3" | ||
| ], | ||
| input_shapes={ | ||
| "raw_outputs/box_encodings": (1, 1917, 4), | ||
| "raw_outputs/class_predictions": (1, 1917, 91), | ||
| }, | ||
| ) | ||
| converter.allow_custom_ops = True | ||
| converter.inference_type = tf.lite.constants.FLOAT | ||
| tflite_model = converter.convert() | ||
| np.random.seed(0) | ||
| box_encodings = np.random.uniform(size=(1, 1917, 4)).astype('float32') | ||
| class_predictions = np.random.uniform(size=(1, 1917, 91)).astype('float32') | ||
| tflite_output = run_tflite_graph(tflite_model, [box_encodings, class_predictions]) | ||
| tvm_output = run_tvm_graph(tflite_model, [box_encodings, class_predictions], | ||
| ["raw_outputs/box_encodings", "raw_outputs/class_predictions"], num_output=4) | ||
| # check valid count is the same | ||
| assert tvm_output[3] == tflite_output[3] | ||
| valid_count = tvm_output[3][0] | ||
| tvm_boxes = tvm_output[0][0][:valid_count] | ||
| tvm_classes = tvm_output[1][0][:valid_count] | ||
| tvm_scores = tvm_output[2][0][:valid_count] | ||
| # check the output data is correct | ||
| tvm.testing.assert_allclose(np.squeeze(tvm_boxes), np.squeeze(tflite_output[0]), rtol=1e-5, atol=1e-5) | ||
| tvm.testing.assert_allclose(np.squeeze(tvm_classes), np.squeeze(tflite_output[1]), rtol=1e-5, atol=1e-5) | ||
| tvm.testing.assert_allclose(np.squeeze(tvm_scores), np.squeeze(tflite_output[2]), rtol=1e-5, atol=1e-5) | ||
|
|
||
|
|
||
| ####################################################################### | ||
| # Mobilenet | ||
| # --------- | ||
|
|
@@ -1573,6 +1618,9 @@ def test_forward_mediapipe_hand_landmark(): | |
| # Logical | ||
| test_all_logical() | ||
|
|
||
| # Detection_PostProcess | ||
| test_detection_postprocess() | ||
|
|
||
| # End to End | ||
| test_forward_mobilenet_v1() | ||
| test_forward_mobilenet_v2() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.