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 random noise augmentation to object detection #654

Merged
merged 30 commits into from
Dec 29, 2021

Conversation

SiddhantBahuguna
Copy link
Contributor

@SiddhantBahuguna SiddhantBahuguna commented Nov 29, 2021

With regards to an issue cf. #730 Extends the list of supported data augmentations,
This PR introduces the following modifications:

It adds Gaussian noise as an augmentation


from doctr.transforms import GaussianNoise
import torch
transfo = GaussianNoise(0., .25) 
output = transfo(torch.rand((3, 224, 224))) # input image as torch.Tensor

gn1

It adds a unittest for the same class

Your feedback is highly welcomed :)

@SiddhantBahuguna SiddhantBahuguna added the ext: references Related to references folder label Nov 29, 2021
@SiddhantBahuguna SiddhantBahuguna self-assigned this Nov 29, 2021
@codecov
Copy link

codecov bot commented Nov 29, 2021

Codecov Report

Merging #654 (94535b1) into main (c72da96) will decrease coverage by 0.01%.
The diff coverage is 91.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #654      +/-   ##
==========================================
- Coverage   96.00%   95.99%   -0.02%     
==========================================
  Files         129      129              
  Lines        4807     4818      +11     
==========================================
+ Hits         4615     4625      +10     
- Misses        192      193       +1     
Flag Coverage Δ
unittests 95.99% <91.66%> (-0.02%) ⬇️

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

Impacted Files Coverage Δ
doctr/transforms/modules/pytorch.py 97.67% <91.66%> (-2.33%) ⬇️
doctr/transforms/modules/base.py 94.44% <0.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 c72da96...94535b1. Read the comment docs.

@charlesmindee charlesmindee changed the title Minor aug feat: Minor aug Nov 29, 2021
@charlesmindee charlesmindee changed the title feat: Minor aug feat: Minor augmentations obj. detection Nov 29, 2021
@fg-mindee fg-mindee added the topic: object detection Related to the task of object detection label Nov 29, 2021
@fg-mindee
Copy link
Contributor

fg-mindee commented Nov 29, 2021

The modifications seem to be highly similar to #648, is there a reason to have them both?
I suggest to first check my feedback on the other PR, fix flake8 here and we'll go from there 👌

@SiddhantBahuguna
Copy link
Contributor Author

The modifications seem to be highly similar to #648, is there a reason to have them both? I suggest to first check my feedback on the other PR, fix flake8 here and we'll go from there ok_hand

Yes, this PR introduces random horizontal and vertical flip :)

@fg-mindee
Copy link
Contributor

Yes, this PR introduces random horizontal and vertical flip :)

Alright, we if you open several PRs in parallel, in order to avoid conflict and ease the review, it's better if they are independent. Here you have the same modifications appearing in both PRs 😅

@SiddhantBahuguna
Copy link
Contributor Author

Yes, this PR introduces random horizontal and vertical flip :)

Alright, we if you open several PRs in parallel, in order to avoid conflict and ease the review, it's better if they are independent. Here you have the same modifications appearing in both PRs sweat_smile

Yup, I am making changes in these ones as well :) Thanks

@SiddhantBahuguna
Copy link
Contributor Author

SiddhantBahuguna commented Dec 2, 2021

I am getting a ValueError when I change the batch_size from 8 to any other size.
ValueError: could not broadcast input array from shape (9,5) into shape (9,4).
9 being the number of artefacts and 4 being the box coordinates for each batch
Traceback below:

images[id], bbox[id] = rotate(images[id], bbox[id], angle[id] if bool(

Could you please take a look:) Thanks a lot!

@fg-mindee
Copy link
Contributor

I am getting a ValueError when I change the batch_size from 8 to any other size. ValueError: could not broadcast input array from shape (9,5) into shape (9,4). 9 being the number of artefacts and 4 being the box coordinates for each batch

That means the dimensions are most likely interpreted in the wrong order 🙃

Traceback below:

images[id], bbox[id] = rotate(images[id], bbox[id], angle[id] if bool(

? that's the one causing the error but not the traceback :) (traceback = the complete error message + tracing you get when you run your code)

Also flake8 isn't happy 😅

@fg-mindee
Copy link
Contributor

Mind merging main into this please? #691 has changed a few things 👍

@fg-mindee
Copy link
Contributor

Would you mind resolving the conflicts so that we can merge the PR? 🙏

@SiddhantBahuguna
Copy link
Contributor Author

SiddhantBahuguna commented Dec 17, 2021

Would you mind resolving the conflicts so that we can merge the PR? pray

Yup, I have resolved the conflicts and have fixed the problem that was causing us to choose arbitrary batch_sizes. Doing some minor code style fixes ta the moment before I push

Copy link
Contributor

@fg-mindee fg-mindee 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 PR! As discussed, the PR is too massive to correctly review it. I suggest we do several PRs to progressively integrate:

  • uniform photometric transformations (noise, blur, etc.)
  • non-uniform photometric transformations (shadows, etc.)
  • geometric transformations (flips, rotations, crops, etc.)

Ideally, if we could have those as doctr.transforms (working on PIL or Torch/TF tensors) that would be perfect! I'll open an issue to track this 👌

.idea/.gitignore Outdated Show resolved Hide resolved
Copy link
Contributor

@fg-mindee fg-mindee left a comment

Choose a reason for hiding this comment

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

The PR is massive, let's narrow it down to photometric augmentations as suggested previously. For instance, this PR could be only about adding a Noise augmentation. Everything else needs to be taken out, it's way too big for me to perform a careful review

On that note, if we use the dataloader, we do the transformation on pytorch tensor. Considering the operation you are doing in numpy, you can perfectly implement them in PyTorch or TensorFlow. In your case, you want to use it for a PyTorch script, so :

references/obj_detection/constants.py Outdated Show resolved Hide resolved
Copy link
Contributor

@fg-mindee fg-mindee left a comment

Choose a reason for hiding this comment

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

Thanks, added some comments!

doctr/transforms/modules/pytorch.py Outdated Show resolved Hide resolved
doctr/transforms/modules/pytorch.py Outdated Show resolved Hide resolved
doctr/transforms/modules/pytorch.py Outdated Show resolved Hide resolved
references/obj_detection/train_pytorch.py Outdated Show resolved Hide resolved
references/obj_detection/utils.py Outdated Show resolved Hide resolved
@fg-mindee fg-mindee changed the title feat: Minor augmentations obj. detection feat: Added random noise augmentation to object detection Dec 24, 2021
@fg-mindee
Copy link
Contributor

fg-mindee commented Dec 24, 2021

Also, you'll need to add unittest for this transformation

@fg-mindee fg-mindee added topic: documentation Improvements or additions to documentation module: transforms Related to doctr.transforms framework: pytorch Related to PyTorch backend labels Dec 24, 2021
@SiddhantBahuguna SiddhantBahuguna added the ext: tests Related to tests folder label Dec 28, 2021
@SiddhantBahuguna SiddhantBahuguna added this to the 0.5.0 milestone Dec 28, 2021
Copy link
Contributor

@fg-mindee fg-mindee left a comment

Choose a reason for hiding this comment

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

Looking good, thanks!

Comment on lines 42 to 47

Args:
freeze_until (str, optional): last layer to freeze
start_lr (float, optional): initial learning rate
end_lr (float, optional): final learning rate
num_it (int, optional): number of iterations to perform
Copy link
Contributor

Choose a reason for hiding this comment

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

This was removed on purpose, it's not accurate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ext: references Related to references folder ext: tests Related to tests folder framework: pytorch Related to PyTorch backend module: transforms Related to doctr.transforms topic: documentation Improvements or additions to documentation topic: object detection Related to the task of object detection type: new feature New feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants