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

feat: Added shadow augmentation for all backends #811

Merged
merged 5 commits into from
Feb 24, 2022
Merged

Conversation

fg-mindee
Copy link
Contributor

Following up on #730, this PR introduces the following modifications:

  • adds RandomShadow augmentation
  • adds unittests
  • adds documentation

The following snippet:

import matplotlib.pyplot as plt
from doctr.io.image import read_img_as_tensor
from doctr.transforms import RandomShadow

transform = RandomShadow((.2, .8))
img = read_img_as_tensor("path/to/your/image.jpg")
plt.imshow(transform(img).numpy()); plt/axis('off'); plt.show()

yields:
shadow_sample

Briefly:

  • this first creates a 4-point polygon with 1 side on the top edge of the image
  • the polygon is rotated & expanded
  • the polygon is filled with 1s
  • we apply an intensity gradient (so that the shadow fades as we go further from the source)
  • with TF or PyTorch we overlay this after applying gaussian blur (a sharp shadow is not very believable)

Apart from filling the polygons, everything is in pure numpy until we overlay with the tensor image!

Any feedback is welcome!

@fg-mindee fg-mindee added ext: tests Related to tests folder module: transforms Related to doctr.transforms type: new feature New feature ext: docs Related to docs folder labels Jan 20, 2022
@fg-mindee fg-mindee added this to the 0.6.0 milestone Jan 20, 2022
@fg-mindee fg-mindee self-assigned this Jan 20, 2022
Copy link
Collaborator

@charlesmindee charlesmindee left a comment

Choose a reason for hiding this comment

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

Thanks for this tranform, only a small comment

doctr/transforms/functional/base.py Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Feb 21, 2022

Codecov Report

Merging #811 (9b0433f) into main (bf2d4ca) will decrease coverage by 0.05%.
The diff coverage is 95.65%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #811      +/-   ##
==========================================
- Coverage   96.01%   95.95%   -0.06%     
==========================================
  Files         131      131              
  Lines        4941     5073     +132     
==========================================
+ Hits         4744     4868     +124     
- Misses        197      205       +8     
Flag Coverage Δ
unittests 95.95% <95.65%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
doctr/transforms/modules/tensorflow.py 92.90% <90.90%> (-0.16%) ⬇️
doctr/transforms/modules/pytorch.py 97.14% <91.66%> (-1.17%) ⬇️
doctr/transforms/functional/base.py 95.31% <96.00%> (+1.56%) ⬆️
doctr/transforms/functional/pytorch.py 100.00% <100.00%> (ø)
doctr/transforms/functional/tensorflow.py 100.00% <100.00%> (ø)
doctr/models/detection/linknet/base.py 88.79% <0.00%> (-5.19%) ⬇️
doctr/models/predictor/tensorflow.py 100.00% <0.00%> (ø)
doctr/models/detection/linknet/pytorch.py 98.86% <0.00%> (ø)
doctr/models/detection/linknet/tensorflow.py 98.66% <0.00%> (ø)
doctr/models/predictor/pytorch.py 97.22% <0.00%> (+0.07%) ⬆️
... and 2 more

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 bf2d4ca...9b0433f. Read the comment docs.

@fg-mindee
Copy link
Contributor Author

Ready for review @charlesmindee @SiddhantBahuguna 😁

Copy link
Collaborator

@charlesmindee charlesmindee left a comment

Choose a reason for hiding this comment

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

Thanks!

@fg-mindee fg-mindee merged commit 0f79736 into main Feb 24, 2022
@fg-mindee fg-mindee deleted the shadow-aug branch February 24, 2022 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext: docs Related to docs folder ext: tests Related to tests folder module: transforms Related to doctr.transforms type: new feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants