Skip to content

Added GaussianBlur transform #2658

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

Merged
merged 18 commits into from
Oct 7, 2020
Merged

Conversation

tejank10
Copy link
Contributor

@tejank10 tejank10 commented Sep 9, 2020

This PR addresses issue #2635. It adds GaussianBlur image transformation. It takes a range of sigma as input. It picks a sigma for Gaussian kernel at random and applies the kernel to the image.

  • Implement the transform
  • Add tests
  • Add docs

Let me know your thoughts @vfdev-5, @yaox12 on where could it be possibly improved.

@oke-aditya
Copy link
Contributor

Small linting errors.

./torchvision/transforms/functional_tensor.py:473:16: E225 missing whitespace around operator
./torchvision/transforms/functional_tensor.py:482:23: E221 multiple spaces before operator
./torchvision/transforms/functional_tensor.py:483:22: E226 missing whitespace around arithmetic operator
./torchvision/transforms/functional_tensor.py:1001:31: E226 missing whitespace around arithmetic operator
./torchvision/transforms/functional_tensor.py:1002:19: E221 multiple spaces before operator

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Sep 17, 2020

@tejank10 thanks for the PR and sorry for delay.

Finally I think the API we would like is with kernel_size and sigma:

# functional.py
def gaussian_blur(img: Tensor, kernel_size: int, sigma: float) -> Tensor:

The main problem is with PIL which can apply kernels larger than 5x5. Maybe, a solution can be to reuse torch implementation for that : PIL -> np.array -> torch.Tensor -> F_t.gaussian_blur -> np.array -> PIL

About your implementation, I'll comment the things where I have questions.

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Sep 18, 2020

@tejank10 OK, let's work on this PR the following way:

  • implement F_t.gaussian_blur(img: Tensor, kernel_size: int, sigma: float) which should be close to opencv's implementation : kernel creation, padding, etc (maybe, this is how it is done in opencv).
  • implement tests

I propose you to work on F_t.gaussian_blur if you do not mind and I'll work on tests and commit my modifications directly to this PR. How does it sound ?

EDIT: I'll also push some modifications of F.gaussian_blur on how to dispatch between PIL and torch Tensor.

@tejank10
Copy link
Contributor Author

Sounds good, will update the API.

@vfdev-5 vfdev-5 force-pushed the rand_gauss_blur_patch branch from c43c414 to 02ad333 Compare September 28, 2020 10:34
@vfdev-5
Copy link
Collaborator

vfdev-5 commented Sep 28, 2020

@yaox12 how about this API ?

@vfdev-5 vfdev-5 requested a review from fmassa September 28, 2020 12:24
@codecov
Copy link

codecov bot commented Sep 28, 2020

Codecov Report

Merging #2658 into master will increase coverage by 0.15%.
The diff coverage is 86.86%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2658      +/-   ##
==========================================
+ Coverage   72.75%   72.90%   +0.15%     
==========================================
  Files          96       96              
  Lines        8309     8396      +87     
  Branches     1292     1315      +23     
==========================================
+ Hits         6045     6121      +76     
- Misses       1871     1878       +7     
- Partials      393      397       +4     
Impacted Files Coverage Δ
torchvision/transforms/transforms.py 81.25% <81.48%> (+0.32%) ⬆️
torchvision/transforms/functional.py 80.44% <81.81%> (+0.07%) ⬆️
torchvision/transforms/functional_tensor.py 73.91% <94.73%> (+1.36%) ⬆️
torchvision/transforms/functional_pil.py 66.19% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 754c954...94477dc. Read the comment docs.

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Sep 28, 2020

@tejank10 we have to improve coverage by executing all input checkings and asserting that they raise correct exception. Can you work on that too ?

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Oct 1, 2020

@tejank10 do you plan to work on this PR this week ? Such that we do not do the same things without syncing. Otherwise, I'll rework everything tomorrow.

@tejank10
Copy link
Contributor Author

tejank10 commented Oct 1, 2020

Yeah, I'll be working on this PR this week.

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Oct 5, 2020

@tejank10 could you please push all your work today if any. I'll finalize today / tomorrow this PR.

@vfdev-5
Copy link
Collaborator

vfdev-5 commented Oct 6, 2020

@tejank10 I'll fix broken CI and merge conflict today. Let me know if you want to push some other updates. Thanks

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Thanks a lot @tejank10 and @vfdev-5 !

@fmassa fmassa merged commit 4106dbb into pytorch:master Oct 7, 2020
@vfdev-5 vfdev-5 mentioned this pull request Oct 8, 2020
bryant1410 pushed a commit to bryant1410/vision-1 that referenced this pull request Nov 22, 2020
* Added GaussianBlur transform

* fixed linting

* supports fixed radius for kernel

* [WIP] New API for gaussian_blur

* Gaussian blur with kernelsize and sigma API

* Fixed implementation and updated tests

* Added large input case and refactored gt into a file

* Updated docs

* fix kernel dimesnions order while creating kernel

* added tests for exception handling of gaussian blur

* fix linting, bug in tests

* Fixed failing tests, refactored code and other minor fixes

Co-authored-by: vfdev-5 <[email protected]>
vfdev-5 added a commit to Quansight/vision that referenced this pull request Dec 4, 2020
* Added GaussianBlur transform

* fixed linting

* supports fixed radius for kernel

* [WIP] New API for gaussian_blur

* Gaussian blur with kernelsize and sigma API

* Fixed implementation and updated tests

* Added large input case and refactored gt into a file

* Updated docs

* fix kernel dimesnions order while creating kernel

* added tests for exception handling of gaussian blur

* fix linting, bug in tests

* Fixed failing tests, refactored code and other minor fixes

Co-authored-by: vfdev-5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants