You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Depending on the input image size, upsampled feature maps with nn.Upsample don't always match the size of the skip connection. This is a known issue, some reference links:
Replacing nn.Upsample with torch.nn.functional.interpolate seems to be the recommended solution.
To Reproduce
Here's a snippet using PP-LiteSeg. The dataset is cityscapes, but that's not important, the image size is the important factor. I imagine that the issue is in all models using nn.Upsample and concatenating with skip connections:
File ".../src/super_gradients/training/models/segmentation_models/ppliteseg.py", line 52, in forward
atten = torch.cat([*self._avg_max_spatial_reduce(x, use_concat=False), *self._avg_max_spatial_reduce(skip, use_concat=False)], dim=1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 66 but got size 65 for tensor number 2 in the list.
Expected behavior
Fully convolutional segmentation models should work for all input image sizes.
Environment:
Ubuntu
super-gradients v3.0.7
PyTorch 1.11
The text was updated successfully, but these errors were encountered:
TLDR: One cannot feed arbitrary-sized image to the model.
I believe the root cause of the problem is that input image has a size that is not integer divisible by a maximum stride of the backbone (32).
In this case backbone produces feature maps that has size that is not a power of two.
Indeed, explicitly specifying output size for upsample operations could patch this.
However, this would work only for interpolation-based upsampling and not for nn.PixelShuffle or nn.ConvTranspose2D upsampling.
We definitely will look into it, but as of now I suggest to preprocess input images to have their size that is divisible by 32.
Describe the bug
Depending on the input image size, upsampled feature maps with
nn.Upsample
don't always match the size of the skip connection. This is a known issue, some reference links:output_size
argument toUpsample
forward method (just like forConvTranspose
Modules) pytorch/pytorch#71877Replacing
nn.Upsample
withtorch.nn.functional.interpolate
seems to be the recommended solution.To Reproduce
Here's a snippet using PP-LiteSeg. The dataset is cityscapes, but that's not important, the image size is the important factor. I imagine that the issue is in all models using
nn.Upsample
and concatenating with skip connections:Results in an error:
Expected behavior
Fully convolutional segmentation models should work for all input image sizes.
Environment:
The text was updated successfully, but these errors were encountered: