G-API: API for configuring model output precision for IE backend#22583
Conversation
|
@smirnov-alexey Could you have a look, please? |
|
|
||
| The function is used to set an output precision for model. | ||
|
|
||
| @param precision Precision in OpenCV format. |
There was a problem hiding this comment.
Need to explain what is the opencv format.
@alalek Could you explain how to point to opencv types: https://docs.opencv.org/4.x/d1/d1b/group__core__hal__interface.html#ga32b18d904ee2b1731a9416a8eef67d06 in doxygen.
| const ParamDesc::precision_variant_t &output_precision) { | ||
| switch (output_precision.index()) { | ||
| case ParamDesc::precision_variant_t::index_of<ParamDesc::precision_t>(): { | ||
| auto precision = toIE(cv::util::get<ParamDesc::precision_t>(output_precision)); |
smirnov-alexey
left a comment
There was a problem hiding this comment.
Overall looks great, thanks!
|
@dmatveev Could you have a look, please? |
0ea293f to
0166437
Compare
dmatveev
left a comment
There was a problem hiding this comment.
Fine with changes but please keep comments in mind
| // NB: cv::util::monostate is default value that means precision wasn't specified. | ||
| using precision_variant_t = cv::util::variant<cv::util::monostate, | ||
| precision_t, | ||
| precision_map_t>; |
There was a problem hiding this comment.
Can you please document the cases in this variant?
My understanding (I haven't read the rest of the patch yet) is that precision_t case is for single output layer, right? And map is for multi-output case?
There was a problem hiding this comment.
No, user can do:
params.cfgOutputPrecision(`CV_16F`) // will be applied for all layers.
or specify certain layers:
params.cfgOutputPrecision({{"layer0", CV_16F}}); // only layer0 has changed precision
There was a problem hiding this comment.
// will be applied for all layers
Well I failed to guess that. :)
| , {} | ||
| , {} | ||
| , {} | ||
| , {} |
There was a problem hiding this comment.
It must be reorganized, I'm afraid of touching it, since it'll cause lot's of changes.
|
|
||
| The function is used to set an output precision for model. | ||
|
|
||
| @param precision Precision in OpenCV format. |
| @param precision Precision in OpenCV format. | ||
| @return reference to this parameter structure. | ||
| */ | ||
| Params<Net>& cfgOutputPrecision(detail::ParamDesc::precision_t precision) { |
There was a problem hiding this comment.
ah this mixture of CamelCase and snake_case_t :)
| : desc{ model, weights, device, {}, {}, {}, 0u, 0u, | ||
| detail::ParamDesc::Kind::Load, true, {}, {}, {}, 1u, | ||
| {}, {}, {}, {}}, | ||
| {}, {}, {}, {}, {}}, |
| std::vector<std::string> input_layers; | ||
| std::vector<std::string> output_layers; | ||
| std::map<std::string, std::string> config; | ||
| cv::util::optional<int> out_precision; |
There was a problem hiding this comment.
So here it is int, not a map of ints?
There was a problem hiding this comment.
Config has parameter output_precision which is applied for all output layers. There is no need to have per layer precision for tool (so far...)
| if (infer_params.out_precision) { | ||
| pp->cfgOutputPrecision(infer_params.out_precision.value()); | ||
| } |
There was a problem hiding this comment.
No multi-output cases supported? What if the user writes such a config? Would it be rejected gracefully?
There was a problem hiding this comment.
Multi-output case is supported. User can only define precision for all output layers. Answered above
| const auto ie_type = toCV(desc.getPrecision()); | ||
| if (ie_type != mat.type()) { | ||
| std::stringstream ss; | ||
| ss << "Failed while copying blob from IE to OCV: " |
There was a problem hiding this comment.
Also, I doubt if multi-line exception text is useful. At least a single-liner is easier to grep
| static void configureOutputPrecision(const IE::OutputsDataMap &outputs_info, | ||
| const ParamDesc::precision_variant_t &output_precision) { | ||
| switch (output_precision.index()) { | ||
| case ParamDesc::precision_variant_t::index_of<ParamDesc::precision_t>(): { |
0166437 to
a6fbd82
Compare
| } | ||
| } | ||
|
|
||
| TEST(TestAgeGenderIE, ChangeOutputPrecision) |
There was a problem hiding this comment.
It must be refactoring asap. Adding new test brings lot's of copy-paste stuff.
|
@dmatveev @asmorkalov Do you mind merging it? |
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.
Overview
This
cfgOutputPrecisionhandle is partially introduced/discussed there: #22522