Repository navigation
Conversation
tile up to size 2048, 2048 to get closer to 1 s runtime for canny
We really only need to know if sum > 0, not the actual value, so can use numpy.unique on the masked values instead.
When mask=None, we can avoid binary morphology and just set the edge values to zero instead.
avoid overhead of smoothing the mask when it is all ones.
Contributor
Author
|
The CI failure is unrelated. |
Member
Contributor
Author
Thanks for pointing out that PR. I had not noticed it previously, but should have done a search here first! I do like the clarity of the larger refactoring in yours. Let me review it and then see about adding any needed commits to your branch (it does not appear to have a corresponding change to 5757c11, which was the key change here on the GPU side). |
2 of 9 tasks
Member
|
👍 Yes I noticed your excellent use of |
Contributor
Author
|
I have now added the performance improvements here to #4342, so will close this PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
UPDATE
I have marked this as WIP due to a similar preceding PR at #4342. It probably makes more sense to merge this PR into that one.
Description
This PR makes multiple independent changes to the Canny feature detection code to improve performance. It will be easiest to review the commits in isolation as they each modify independent things. The table below shows the benchmark result for each commit here.
Commits 5ab8429 and a69f6a8 only help for the case when
mask=None. Overall, the reduction in runtime for the benchmark is 32% in the unmasked case and 12% in the masked case.Commit 5757c11 gives only a minor improvement here, but makes an order of magnitude difference if using CuPy for the array module (
cupyx.scipy.ndimage.sumis not very efficient for a large number of very small labeled regions). The poor performance of this function in a CuPy-based implementation was the reason I started looking at performance here in the first place.Commit a69f6a8 provides a substantial benefit, but this commit does result in small differences near the image edge as generated via results from the following script. Qualitatively, they look equivalent to me, but the results are not pixelwise identical to before near the edge.
Checklist
./doc/examples(new features only)./benchmarks, if your changes aren't covered by anexisting benchmark
For reviewers
later.
__init__.py.doc/release/release_dev.rst.