cuda4dnn: optimizations for swish, mish, sigmoid, region, resize based ops, transpose, identity-conv fusion#17200
Merged
alalek merged 2 commits intoopencv:masterfrom May 9, 2020
Conversation
tompollok
reviewed
May 2, 2020
6 tasks
6 tasks
a-sajjad72
pushed a commit
to a-sajjad72/opencv
that referenced
this pull request
Mar 30, 2023
cuda4dnn: optimizations for swish, mish, sigmoid, region, resize based ops, transpose, identity-conv fusion * bunch of optimizations * more accurate implementation for mish
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.
Pull Request Readiness Checklist
Mish (+ swish and sigmoid):
This activation is used in YOLOv4. Surprisingly, the mish kernels are compute-bound instead of being bandwidth-bound. The first convolution in YOLOv4 takes less time than the fused bias mish activation step.
Mish is a composition of several functions: tanh(log(1 + exp(x))). Hence, it is very likely that there is a very good approximation or simplification to the mish function (clearly the log isn't necessary since tanh is a composition over e^x). This PR introduces a fast numerically stable implementation of the mish activation.
Details of the approximation can be found here.
Based on similar reasoning, good fast approximations to swish and sigmoid were also added.
Identity is fused with convolution layer:
Activations would not be fused with convolution if an identity layer is present between them. This happens in the case of Mask RCNN: the final sigmoid operation is not fused with the preceding convolution operation.
This kernel is compute-bound if the sigmoid approximation mentioned above is not used. The timings reported here are with the approximation.
Others:
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.