question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Random horizontal and vertical flips doesn't work with bbox

See original GitHub issue

🐛 Bug

Random{Horizontal/Vertical}Flip for Transform2D and Transform3D doesn’t work. See image attached.

EDIT: RandomRotation always shows the same behavior. RandomCrop, CenterCrop, RandomResizedCrop, RandomErasing and RandomPerspective are fine (checked 2D version).

To Reproduce

!wget https://tinypng.com/images/social/website.jpg -O panda.jpg

from kornia import augmentation as K

tfm= K.AugmentationSequential(
    K.RandomVerticalFlip(p=1.)
    data_keys=["input", "bbox"]),
    return_transform=False,
    same_on_batch=False
)


img = cv2.imread("panda.jpg", cv2.IMREAD_COLOR)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
h, w = img.shape[:2]

image= image_to_tensor(img).float() / 255.

bbox = torch.tensor([[[355,10],[660,10],[660,250],[355,250]]])
tfm(image, bbox.float())

Original image: image

Transformed image: image

Original box (in xyxy): tensor([[355., 10., 660., 250.]]) Transformed box (in xyxy): tensor([[ 355., -246., 660., -6.]])

Expected behavior

image

Correct transformed box (in xyxy): tensor([[355., 260., 660., 500.]])

Environment

pytorch 1.8.1 Kornia 0.5.6

Addition comments

Shortly, I’ll make a PR

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
edgarribacommented, Jul 22, 2021

@hal-314 please, make sure to add some tests in PR that fixes the issue

0reactions
edgarribacommented, Oct 2, 2021
Read more comments on GitHub >

github_iconTop Results From Across the Web

bbox vertical flip is not handled correctly when aug test #2805
If I set random vertical flip, bbox transform in mmdet/core/bbox/transforms.py handle the vertical flip via horizontal flip.
Read more >
Data Augmentation For Bounding Boxes: Flipping
For example, an augmentation which horizontally flips the image for classification tasks will like look the one above.
Read more >
Augmentations, Data Cleaning and Bounding Boxes - Kaggle
p=0.5 means that with a probability of 50%, the transform will flip the image horizontally, and with a probability of 50%, the transform...
Read more >
class albumentations.augmentations.transforms. Blur
Blur the input image using a random-sized kernel. ... -1 for both vertical and horizontal flipping (which is also could be seen as...
Read more >
Geometric transforms (augmentations.geometric.transforms)
Rotation happens around the center of the image, not the top left corner as in ... Flip the input either horizontally, vertically or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found