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

Reversible Resize #974

Closed
wants to merge 2 commits into from
Closed

Reversible Resize #974

wants to merge 2 commits into from

Conversation

Dipet
Copy link
Collaborator

@Dipet Dipet commented Jul 30, 2021

I tried to implement the interface for Test Time Augmentations (TTA) using ReplayCompose API.

If some transform could support reverse operation we must implement these functions:

  • get_reverse_args - to save all needed parameters to do reverse transformation
  • reverse_image - to reverse images and masks
  • reverse_bbox - to reverse bboxes
  • reverse_keypoint - to reverse keypoints.

Example:

import numpy as np
import albumentations as A

t = A.ReversibleCompose(
    [A.Resize(512, 512, p=1)], bbox_params=A.BboxParams("pascal_voc"), keypoint_params=A.KeypointParams("xy")
)
img = np.empty([100, 100, 3], dtype=np.uint8)
bboxes = [(0, 0, 10, 10, 1)]
keypoints = [(10, 20)]

res = t(image=img, bboxes=bboxes, keypoints=keypoints, test="test")
res = t.reverse(**res)

assert np.allclose(np.array(bboxes), np.array(res["bboxes"]))
assert np.allclose(np.array(keypoints), np.array(res["keypoints"]))

@glenn-jocher
Copy link

@Dipet thanks for the PR! This would be super useful.

For the TTA use case we do not need to reverse the images, only the boxes/keypoints. What's the use case for reversing image transforms? Aren't many image transforms non-reversible in any case?

@Dipet
Copy link
Collaborator Author

Dipet commented Aug 12, 2021

At the moment, this is just a blank.

For the TTA use case we do not need to reverse the images, only the boxes/keypoints. What's the use case for reversing image transforms? Aren't many image transforms non-reversible in any case?

We usually use the same function for segmentation masks, this function is only needed for them.

@glenn-jocher
Copy link

@Dipet oh got it, ok! The main thing i was worried about was the extra cost in reversing a full image transform, but if only the keypoints are reversed and not the full images that's perfect.

@Dipet
Copy link
Collaborator Author

Dipet commented Aug 12, 2021

@Dipet oh got it, ok! The main thing i was worried about was the extra cost in reversing a full image transform, but if only the keypoints are reversed and not the full images that's perfect.

Yes, only provided data will be reversed. Perhaps I will remove the reverse_image and leave only the reverse_mask.

@Dipet Dipet marked this pull request as draft September 29, 2021 18:07
@agporto
Copy link

agporto commented Feb 10, 2023

Is this still planned? It would super useful to have this feature.

@hsuominen
Copy link

+1, this would be great to have

@ternaus ternaus closed this Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants