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

Resizing with single value after padsquare(from augly) gives RuntimeError: stack expects each tensor to be equal size #142

Open
jamesrobertwilliams opened this issue Oct 15, 2021 · 1 comment

Comments

@jamesrobertwilliams
Copy link

🐛 Bug

I am facing a bit of a bizzare problem: I have a bunch of different sized images and I am trying to train+infer on these, and I have the following example transform code:

        self.infer_transform = transforms.Compose([
            imaugs.PadSquare(p=1),
            transforms.Resize([384], interpolation=torchvision.transforms.InterpolationMode.BICUBIC),
            transforms.ToTensor(),
            transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])

When I use a batchsize >1 I get thrown this:

RuntimeError: stack expects each tensor to be equal size, but got [3, 384, 384] at entry 0 and [3, 385, 384] at entry 3

I find this really bizarre, since, after PadSquare, when I resize using a single int, it should give me a square image back - but it seems like it does not... why is this? is this a bug? It almost seems like some round-off error (got [3, 384, 384] at entry 0 and [3, 385, 384]).

Hoever, if I do this:

        self.infer_transform = transforms.Compose([
            imaugs.PadSquare(p=1),
            transforms.Resize((384,384), interpolation=torchvision.transforms.InterpolationMode.BICUBIC),
            transforms.ToTensor(),
            transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])])

it works fine...

What is the reason behind this? I am perplexed! When I try out sample images in say colab, they seem to have the same size...

Unfortunately, I am loading some 150k images using imagefolder, so I am not able to inspect the image directly.

@jbitton
Copy link
Contributor

jbitton commented Dec 17, 2021

Hi @jamesrobertwilliams, I'm so unbelievably sorry I didn't see this issue until now! Is this issue still persisting for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants