Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create CUDA backend support for dnn_superres #2599

Merged
merged 3 commits into from
Jul 13, 2020

Conversation

Saafke
Copy link
Contributor

@Saafke Saafke commented Jul 11, 2020

Hi there,

This PR allows users to set CUDA backend in the dnn_superres module. Now users can use their GPU's for inference while upscaling images via the neural networks. I've tried a few images, and I've seen around an 6x increase in speed (GTX 1080Ti).

I'm not sure this is the best way of doing this. Perhaps it is better to also allow users to choose other types of backends? What do you think? I'll wait for the feedback before adding a tutorial (and test?) for this.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under OpenCV (BSD) License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

Not sure if this is the best way. Perhaps better to to create getter for 'net' so user can set backend themselves.
void DnnSuperResImpl::setCUDA()
{
net.setPreferableBackend(cv::dnn::DNN_BACKEND_CUDA);
net.setPreferableTarget(cv::dnn::DNN_TARGET_CUDA);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More robust solution is to proxy these calls instead:

  • setPreferableBackend
  • setPreferableTarget

Otherwise we will get soon setOpenCL, setCUDA_FP16, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean like this? (See new commit)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, good. Should I add a note in the tutorials somewhere? And I don't think a test is needed (or possible) for this right?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this change is straightforward and doesn't require extra documentation or tests.

Copy link
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@alalek alalek merged commit 5588ead into opencv:master Jul 13, 2020
@tompollok
Copy link
Contributor

@Saafke which networks have you tried for upscaling? Are the networks publicly available?

@Saafke
Copy link
Contributor Author

Saafke commented Jul 13, 2020

@Saafke which networks have you tried for upscaling? Are the networks publicly available?

@tompollok It works with all four available models. Check the tutorial for how to use this module. This blog is also helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants