Added Steps support in DNN Slice layer#19546
Conversation
96eaa99 to
af88ecf
Compare
|
@alalek, the code was corrected in accordance with comments. Is it needed to rebase this patch on 3.4 branch? |
We will backport it separately later (there is some CUDA-specific code). |
|
/cc @asenyaev |
af88ecf to
105dfb0
Compare
|
@alalek, rebased on 3.4 branch. |
| 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.
Please add out of range checks for sliceSteps[i][j] access.
| 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.
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.
@alalek, yes, but if it's ok with you, let's separate this optimization activity and implement it not in this scope.
| DictValue steps_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.
Do we want to support this case?
There was a problem hiding this comment.
@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 the issue (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.
Implementation should fallback on CPU code instead of test skipping.
105dfb0 to
303fcbc
Compare
|
Hi, is there any plan to merge this in master? |
|
This patch will be merged to master, but without the CUDA part (CUDA code path will fallback on CPU - it works, but slow) |
|
Ok, is there any issue i can follow about this? |
|
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). |
Merge with extra: opencv/opencv_extra#854
Fixes #18920: added
stepsparameter support for Slice layerPatch to opencv_extra has the same branch name.