G-API: ONNX. Disable unnecessary outputs#18903
Conversation
|
Would you also change the PR's description, please? |
|
@OrestChura @mpashchenkov Friendly reminder. |
|
|
||
| TEST_F(ONNXWithRemap, InferWithDisabledOut) | ||
| { | ||
| useModel("/object_detection_segmentation/faster-rcnn/model/FasterRCNN-10"); |
|
|
||
| std::vector<bool> normalize; | ||
|
|
||
| std::vector<std::string> d_out_names; |
There was a problem hiding this comment.
It make sense to add comment with decoding of field name
There was a problem hiding this comment.
Added comment.
| ti.is_disabled = (std::find(params.d_out_names.begin(), | ||
| params.d_out_names.end(), ti.name) != params.d_out_names.end()) && is_postproc; |
.cfgDisableOutput( { with_layer's_name_that_should_be_disabled, ..., ... } )Can't we achieve the same by calling |
|
@dmatveev, unfortunately no. We use remap functions; ssd-mobilenet, for example, returns four outputs, but we call |
bf4dba2 to
54c88f7
Compare
|
Let's discuss it locally |
e680faa to
4ae74e5
Compare
6407c02 to
f88320d
Compare
| if (original_data != received_data) { | ||
| cv::util::throw_error | ||
| (std::logic_error | ||
| ("OpenCV kernel output parameter was reallocated. \n" |
There was a problem hiding this comment.
Does it make sense to put information that it happened in ONNX backend ?
There was a problem hiding this comment.
Changed message. Added mention about ONNX.
| gapi_out.begin<T>()); | ||
| if (gapi_out.total() > onnx_out.total()) { | ||
| T* gptr = gapi_out.ptr<T>(); | ||
| gptr[size] = static_cast<T>(end_mark); |
There was a problem hiding this comment.
What's the reason of using static_cast ? end_mark and gptr has the same type
There was a problem hiding this comment.
No sense. Fixed.
|
@alalek, can you merge this PR? |
| Params<Net>& cfgPostProc(std::vector<cv::GMatDesc> &&out_metas, | ||
| PostProc &&pp) { | ||
| desc.out_metas = std::move(out_metas); | ||
| desc.custom_post_proc = std::move(pp); | ||
| return *this; | ||
| } |
There was a problem hiding this comment.
I believe doxygen comments are really missing here since the semantics of these methods is not very trivial
5214175 to
a608ec7
Compare
a608ec7 to
61a4100
Compare
dmatveev
left a comment
There was a problem hiding this comment.
👍 follow-up is required on the documentation update, but it shouldn't block the merge.
| /** @brief Configures graph output and sets the post processing function from user. | ||
|
|
||
| The function is used for the case of infer of networks with dynamic outputs. | ||
| Since these networks haven't known output parameters needs provide them for | ||
| construction of output of graph. | ||
| The function provides meta information of outputs and post processing function. | ||
| Post processing function is used for copy information from ONNX infer's result | ||
| to output of graph which is allocated by out meta information. | ||
|
|
||
| @param out_metas out meta information. | ||
| @param pp post processing function, which has two parameters. First is onnx | ||
| result, second is graph output. Both parameters is std::map that contain pair of | ||
| layer's name and cv::Mat. | ||
| @return reference to object of class Params. | ||
| */ |
There was a problem hiding this comment.
Please merge this now open a follow-up task to fix this text.
Disable unnecessary outputs
How it works:
Unnecessary network outputs can be omitted. For example: FRCNN has output with
INT_64data type, which unsupported for OCV. Name of this output is "6381". We can "disable" this output. It works for dynamic output case only when we should remap onnx outputs to g-api out.You can set layer names which you will use in remapping. You should call overload of cfgPostProc function for this.
There are two layers with names "6383" and "6379" will be used for remapping. Data will be remapped from "6383", "6379" to "gapi_out1", "gapi_out2" with remapRcnnPorts function logic (Unfortunately we can't set out_meta for network with dynamic outputs, but we can set own outputs and remap data to them from onnx result).
Disabling is independent of cfgOutputLayers function in this case.
For CNN with static outputs use another logic. We know out_meta and don't need remapping in tis case.
Tests:
Test contains infer for FRCNN. FRCNN output with name "6381" has unsupported type.
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.
Custom build: