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.

Weird bounding box resize values

See original GitHub issue

Describe the bug

I’m trying to resize images to half the width and height. my images are 1200x1600

Reproduction steps

from typing import Dict, Optional, Tuple, Union
import torch
from kornia import augmentation as KA
from kornia.augmentation.random_generator import random_generator as rg
from kornia.constants import Resample


class Resize(KA.RandomResizedCrop):
    def __init__(
        self, size: Tuple[int, int], resample: Union[str, int, Resample] = Resample.BILINEAR.name, *args, **kwargs
    ):
        """Resize the frame.

        Parameters
        ----------
        size : tuple of int
            size (h, w) in pixels of the cropped region
        """
        super().__init__(
            p=1,
            size=size,
            scale=(1, 1),
            ratio=(size[0] / size[1], size[0] / size[1]),
            resample=resample,
            return_transform=False,
            keepdim=True,
            *args,
            **kwargs,
        )

    def __repr__(self) -> str:
        repr = f"size={self.size}, interpolation={self.resample.name}"
        return self.__class__.__name__ + f"({repr}, {super().__repr__()})"

    def generate_parameters(self, batch_shape: torch.Size) -> Dict[str, torch.Tensor]:
        return rg.random_crop_generator(
            batch_shape[0],
            (batch_shape[-2], batch_shape[-1]),
            (batch_shape[-2], batch_shape[-1]),
            resize_to=self.size,
            same_on_batch=self.same_on_batch,
            device=self.device,
            dtype=self.dtype,
        )
KA.AugmentationSequential(            
            Resize(size=(600, 800)),
            data_keys=["input", "bbox_xyxy"],
            same_on_batch=False,
            return_transform=False,
            random_apply=True,
        )
  1. Supply bounding boxes

Expected behavior

I would have expected to see half the values afterwards, yet I get this:

tensor([[458.7130, 505.5780, 482.6980, 522.5638],
        [434.2283, 478.1010, 502.6855, 533.0551],
        [455.2152, 485.5947, 480.1996, 510.5738],
        [530.6680, 421.6481, 559.1501, 464.6122],
        [383.2602, 381.6814, 425.7336, 452.1226],
        [457.7137, 466.6105, 489.1939, 540.0493],
        [544.6592, 518.5671, 577.1389, 558.5338]])

before my bounding boxes look like this

tensor([[ 918., 1012.,  966., 1046.],
        [ 869.,  957., 1006., 1067.],
        [ 911.,  972.,  961., 1022.],
        [1062.,  844., 1119.,  930.],
        [ 767.,  764.,  852.,  905.],
        [ 916.,  934.,  979., 1081.],
        [1090., 1038., 1155., 1118.]])

Environment

wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
# For security purposes, please check the contents of collect_env.py before running it.
python collect_env.py
- PyTorch Version (e.g., 1.0): 1.10
- OS (e.g., Linux): Linux
- How you installed PyTorch (`conda`, `pip`, source): pip
- Build command you used (if compiling from source): -
- Python version: 3.8.12
- CUDA/cuDNN version: 11.5/8
- GPU models and configuration: single gpu
- Any other relevant information:

Additional context

@shijianjian

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
shijianjiancommented, Dec 6, 2021

I will update the cropping functions to be shape-agnoistic, on top of the normalised coordinates (ranged from [0, 1]). Then, I think this issue might be alleviated. Probably start next week or so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resize bounding box according to image - python
My problem was solved within this post by a user named @lenik. Before applying the scale factor to the ground truth box g...
Read more >
Fix bounding box return type in AugmentationSequential #1522
Internally, all transformations are done by representing the four points of a bounding box bbox . Yet if the datakey used is eigher...
Read more >
Resizing bounding box without scaling image - 8321443
I wonder if anyone can assist. I want to change the size of a bounding box without scaling the image i.e the image...
Read more >
How to resize and rotate canvas shapes with react and konva?
But still it may look weird, because shape is chaning its bounding box. As another solution, just keep using rotation for your line....
Read more >
Text Boxes & resizing objects in Illustrator Behaving Strangely
Then, using the bounding box, I drag a corner to resize it, and as I do that, it is generating more rectangles as...
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