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 ChannelShuffle transformation and fixes RandomCrop #768

Merged
merged 7 commits into from
Dec 29, 2021

Conversation

fg-mindee
Copy link
Contributor

@fg-mindee fg-mindee commented Dec 28, 2021

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

The following snippet:

from doctr.io import read_img_as_tensor
from doctr.transforms import ChannelShuffle
import matplotlib.pyplot as plt

img = read_img_as_tensor('/path/to/img.png')
plt.imshow(transfo(img).permute(1, 2, 0).numpy()); plt.axis('off'); plt.show()

with the following image
68231970
produces:
channel_shuffle
(since it's a PNG, the background, which was transparent, is by default cast to black upon reading the image)

Any feedback is welcome!

@fg-mindee fg-mindee added topic: documentation Improvements or additions to documentation type: enhancement Improvement ext: tests Related to tests folder module: transforms Related to doctr.transforms labels Dec 28, 2021
@fg-mindee fg-mindee added this to the 0.5.0 milestone Dec 28, 2021
@fg-mindee fg-mindee self-assigned this Dec 28, 2021
@codecov
Copy link

codecov bot commented Dec 28, 2021

Codecov Report

Merging #768 (6a776c9) into main (8e7b0ee) will decrease coverage by 0.02%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #768      +/-   ##
==========================================
- Coverage   95.99%   95.97%   -0.03%     
==========================================
  Files         129      129              
  Lines        4818     4839      +21     
==========================================
+ Hits         4625     4644      +19     
- Misses        193      195       +2     
Flag Coverage Δ
unittests 95.97% <93.33%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
doctr/transforms/functional/pytorch.py 97.77% <80.00%> (-2.23%) ⬇️
doctr/transforms/functional/tensorflow.py 98.03% <80.00%> (-1.97%) ⬇️
doctr/transforms/modules/base.py 94.52% <100.00%> (+0.07%) ⬆️
doctr/transforms/modules/pytorch.py 98.00% <100.00%> (+0.32%) ⬆️
doctr/transforms/modules/tensorflow.py 92.50% <100.00%> (+0.32%) ⬆️

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 8e7b0ee...6a776c9. Read the comment docs.

charlesmindee
charlesmindee previously approved these changes Dec 29, 2021
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 !

charlesmindee
charlesmindee previously approved these changes Dec 29, 2021
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 the fix!

@fg-mindee
Copy link
Contributor Author

Sorry I had to solve some conflicts after the last commits on main 😅

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

doctr/transforms/functional/pytorch.py Show resolved Hide resolved
doctr/transforms/functional/tensorflow.py Show resolved Hide resolved
min(int(round((start_y + crop_h) * h)), h - 1)
)
croped_img, crop_boxes = F.crop_detection(img, target["boxes"], crop_box)
xmin, ymin = random.uniform(0, 1 - crop_w), random.uniform(0, 1 - crop_h)
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the range of scale and ratio could it not be that if the maximum value of crop_w = math.sqrt(scale / ratio) for instance is chosen, it will be more than 1 and we might end up getting a negative value for the argument: random.uniform(0, 1 - crop_w) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but that's why it's clipped later on!
We clip it at the end to minimize the constraints on the distribution/randomness

Copy link
Contributor

Choose a reason for hiding this comment

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

Its clear now. Thanks!

@fg-mindee fg-mindee merged commit f5b6375 into main Dec 29, 2021
@fg-mindee fg-mindee deleted the channel-shuffle branch December 29, 2021 16:22
@fg-mindee fg-mindee added type: new feature New feature and removed type: enhancement Improvement labels Dec 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext: tests Related to tests folder module: transforms Related to doctr.transforms topic: documentation Improvements or additions to documentation type: new feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants