-
Notifications
You must be signed in to change notification settings - Fork 303
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
Barrel and Pincushion distortions are added. #113
base: main
Are you sure you want to change the base?
Conversation
- Updated code formatting.
Hi @devrimcavusoglu, thank you for your PR! I've glanced through your code and it looks good from what I can see, but it looks like you have a lot of changes that are due to running |
will do ASAP |
@zpapakipos I reverted the black formatting, you can review the changes. I may open another PR perhaps at the end of this week or so for formatting related issues. Btw, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @devrimcavusoglu, thank you for this PR! It looks good overall, nothing major is missing and the augmentations look useful. :) Please address my comments and we'll see if @jbitton has comments as well.
- Intensity added for barrel and pincushion distortions.
Thank you for the review @zpapakipos, I made the according changes to your comments, though I did not change the line-length (black formatting) as the project needs a solid configuration for code style/formatting purposes. For that, I want to address this in a different PR where I will add both configuration files and format the whole codebase according to the rules defined in contributing doc. Thus, my suggestion is to skip code formatting here, and address this on the follow up PR, wdyt ? @jbitton @zpapakipos |
@devrimcavusoglu To follow up on your comment above:
That sounds great, happy to review that if you do it!
I see your reasoning, however @jbitton & I would prefer if you commit clean code, at least to the extent that the lines are <90 cols & tabs are the correct number of spaces, etc. We want to keep the style in the codebase consistent, and we know there are some consistent issues when it comes to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few more changes to request in addition to my comment above. Also, note that your transforms unit tests are failing because the metadata doesn't match the expected metadata, so check what metadata you are getting & fix that please.
- metadata json revised as to convey alphabetical order.
@zpapakipos thank you for the review. I've committed the requested changes. 👍 |
- Adjusted scale added to intensity to better interpret the influence of the scale parameter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few more nitpicky changes, overall looking good to me! Hopefully @jbitton can take a look today too in case she wants any changes.
One other thing to be aware of: I'll be landing #120 soon, which adds support for bounding boxes to all image augmentations. Once that is landed all new image augmentations will also need to define a function in augly/image/utils/bboxes.py
which defines how a bounding box is transformed by that augmentation. Will you be able to help write that function, i.e. do you have a sense of how to compute how an arbitrary pixel in the image's position is changed by these 2 augmentations?
@zpapakipos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@zpapakipos Alright, the latest changes are in. I made a few corrections, as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just added a few last small nits
Also, I want to make sure you saw this part of my comment above:
I plan to land the bounding box PR (#120) on Monday, and then we should rebase this on top & add a function which computes how the bounding box is transformed. I can help with that if needed, but the hard part is that we need to know how to compute how specific coordinates (i.e. the corners of a bounding box) are transformed by these augmentations. |
@zpapakipos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM!! The test images look great and overall the code looks great! Thank you so much for your contribution! @zpapakipos I'll let you take it from here in terms of merging and reviewing upcoming bbox code :)
Thank you @zpapakipos, I'll take a look at #120, but I guess it will be a bit tricky to compute how the bbox transformed with distortions. Tbh, I don't come up with an instant practical solution right now for bboxes. |
@jbitton Thank you for review, I updated the PR with the latest changes. |
Hi @devrimcavusoglu, I spent a few hours working on a function I just wanted to update you so you know where we are at with this. If you have time to take a look & try to get it working on the cases where it's failing, here is my code & test cases which you can copy & use as a starting point: https://colab.research.google.com/drive/12bpBi8J_rCc7bShmUndlVjcSGuNdgPy3?usp=sharing |
Hi @devrimcavusoglu, I have a proposal for how we can pretty quickly merge these changes without you having to wait for me to solve the bounding box problem:
distort_barrel_bboxes_helper(bbox: Tuple, **kwargs) -> Tuple:
raise NotImplementedError("Bounding box support has not yet been added to this augmentation") and distort_pincushion_bboxes_helper(bbox: Tuple, **kwargs) -> Tuple:
raise NotImplementedError("Bounding box support has not yet been added to this augmentation")
def test_DistortBarrel(self):
try:
self.evaluate_class(imaugs.DistortBarrel(a=0.1), fname="distort_barrel")
except NotImplementedError:
pass
else:
self.assertTrue(
False,
"This augmentation doesn't have bounding box support, so should fail with NotImplementedError"
) and def test_DistortPincushion(self):
try:
self.evaluate_class(imaugs.DistortPincushion(a=0.1), fname="distort_pincushion")
except NotImplementedError:
pass
else:
self.assertTrue(
False,
"This augmentation doesn't have bounding box support, so should fail with NotImplementedError"
)
I will work on a PR that adds support for transforming bboxes for these 2 augmentations which I'll merge later, but I don't want that to hold up this PR getting resolved. This way users will be able to use these new augmentations, but they will just receive an error if they try to pass in any bounding boxes to alert them that bboxes are not yet supported for these augs. Please make those changes & update the PR if that sounds good, thanks! |
Hi @zpapakipos, past weekend I did pulled the last changes and rebased already, but I didnt pushed the changes due to the bbox update you are working on. Having said that, I will push the changes as you requested asap. I have play around the notebook you linked, I haven't come up with an immediate solution for that problematic cases. However, I think about one "possible" solution for pincushion, but I do not know if it will work on any cases. Perhaps, you develop the idea from here and improve this approach, and even you may apply it for barrel as well. First of all, when I saw the failed pincushion case, naturally I validated my idea to see if the bbox location (you can think of a center precisely) affects how the pincushion fails. So long story short, there is a pattern for pincushion cases that in what direction the bbox center is from the center of canvas (image) the failing part of pincushion is the same direction (you can try several locations center left, top left, bottom right, etc for bbox and see the resulting pincushion effect). Now, from here, I suggest that we draw the resulting bbox from the current boxes coordinates by expanding the bbox in the same direction as the bbox from center of the image. In other words, let's say the bbox is top left to the image center, then we expanding the resulting bbox only towards top left until hitting the image bounds. It'd be better if you inspect visually to better understand the situation. I believe, this pattern does not apply for barrel distortion, but you can observe a different pattern for that. The last thing I want to say is, it is required to validate this assumption for any case which would be harder. |
That's great, looking forward to seeing your pushed rebased changes @devrimcavusoglu! Remember to add the Once you've published those changes we should be able to land your changes, and then I'll work on a follow-up diff for the bboxes. I'm thinking of doing an easy but slow solution for this & any other hard augmentations that come up -- basically just create an image with the same width & height as the src image, all black except white inside the bbox, run the augmentation on this image, and then get the transformed bbox by computing the min & max white pixels in each dimension in the augmented image. This should be fairly foolproof for any augmentation (that doesn't affect color) but just take longer than the other solutions we've found for other augmentations like |
Hi @zpapakipos, I've updated with the latest changes, I take a look overall, I guess we're good to go. After your review, let me know if any change further is required. |
Great. That seems more solid solution which would work for any augmentation. After all, what I suggested only holds for pincushion distortion. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few formatting fixes & let's make sure the tests pass, otherwise looks good! Thanks for the quick changes :)
Co-authored-by: Zoe Papakipos <[email protected]>
@zpapakipos has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
Hi @devrimcavusoglu, update for you: I imported this PR & tried to get the augmentations working in our internal version of the augly codebase (which is linked to this one, so any change here has to be imported & vice versa). But unfortunately ImageMagick is proving to be a really tricky dependency to add. And as @jbitton mentioned before, we are generally hesitant to add new dependencies to our library so we can keep it relatively lightweight & easy to install (and adding wand as a dependency would add a manual step to the installation process since ImageMagick isn't installable via pypi). Sorry to ask this, but can you please reimplement the |
Well, I see. It is unfortunate that we cannot use imagemagick because it has many distortion methods not only Barrel and Pincushion. The package you referred to uses only implements subset of distortions in their distort method. On the other hand, ImageMagick implements at least 15 different distortion methods. This is a very large drawback not using ImageMagick for potential upcoming distortion implementations to AugLy. However, all in all if it won't be a good fit for AugLy, we may do a research for a new lighter package or implement it without using any additional packages. @zpapakipos @jbitton Unfortunately, at this point I have to ask for you to pick up from here and whether you can continue the work on this PR as I will be dealing with a new upcoming package and need to work on a major rework for another package I and my team maintain. If I will take it back from here it will be delayed too long. I'd really appreciate if you can work on the distortion implementations. |
Related Issue
Fixes #111
Summary
Added barrel and pincushion distortions to
augly.image
module.Unit Tests
Related tests are added, and passing.
Other testing