Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork56.4k
Added Steps support in DNN Slice layer#19546
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
96eaa99 toaf88ecfCompareLupusSanctus commentedMar 3, 2021
@alalek, the code was corrected in accordance with comments. Is it needed to rebase this patch on 3.4 branch? |
alalek commentedMar 3, 2021
We will backport it separately later (there is some CUDA-specific code). |
asmorkalov commentedMar 9, 2021
/cc@asenyaev |
LupusSanctus commentedMar 9, 2021
@alalek, rebased on 3.4 branch. |
alalek left a comment
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.
Thank you for update!
| outputs[i][j] =normalize_axis_range(sliceRanges[i][j], inpShape[j]).size(); | ||
| if (! sliceSteps.empty() && sliceSteps[i][j] >1) | ||
| outputs[i][j] = (outputs[i][j] + sliceSteps[i][j] -1) / sliceSteps[i][j]; |
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.
Please add out of range checks forsliceSteps[i][j] access.
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.
@alalek, checks were added.
| if (dim +1 < dimsNum) | ||
| getSliceRecursive(inpMat, inpIdx, sliceRanges, sliceSteps, dim +1, dimsNum, outputs, outIdx); | ||
| else | ||
| outputs.at<float>(outIdx.data()) = inpMat.at<float>(inpIdx.data()); |
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.
IMHO, provided implementation is really slow.
I believe we should have optimized case for 2D (the last 2 dims) processing at least.
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.
@alalek, yes, but if it's ok with you, let's separate this optimization activity and implement it not in this scope.
| DictValuesteps_dict = layerParams.get("steps"); | ||
| for (int i =0; i <steps_dict.size(); ++i) | ||
| { | ||
| if (steps.get<int>(i) !=1) | ||
| if (steps_dict.get<int>(i) !=1) { | ||
| CV_Error(Error::StsNotImplemented, | ||
| "Slice layer only supports steps = 1"); |
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.
Do we want to support this case?
LupusSanctusMar 25, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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.
@alalek, this case could be useful for opset9, which doesn't support step!=1, however, it means that initially onnx model could not be generated with step value != 1, hence, this check is useless.
Just in case, I've checked the model from theissue (which relates to the PR, where this code block was added), there is no step parameter (in opset9 slice layer "no step parameter" => step=1). Removed this code block.
| if (backend == DNN_BACKEND_OPENCV) | ||
| applyTestTag(target == DNN_TARGET_OPENCL ? CV_TEST_TAG_DNN_SKIP_OPENCL : CV_TEST_TAG_DNN_SKIP_OPENCL_FP16); |
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.
Implementation should fallback on CPU code instead of test skipping.
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.
@alalek, corrected.
OlivierLDff commentedMar 26, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Hi, is there any plan to merge this in master? |
alalek commentedMar 26, 2021
This patch will be merged to master, but without the CUDA part (CUDA code path will fallback on CPU - it works, but slow) |
OlivierLDff commentedMar 26, 2021
Ok, is there any issue i can follow about this? |
alalek commentedMar 26, 2021
Fallback CUDA-CPU-CUDA is slow due to data transfers and synchronization points. Currently CUDA optimizations are maintained by community, so feel free to propose a patch after the merge to master (wait for "(4.x) Merge 3.4" regular PR). |
Uh oh!
There was an error while loading.Please reload this page.
Merge with extra:opencv/opencv_extra#854
Fixes#18920: added
stepsparameter support for Slice layerPatch to opencv_extra has the same branch name.