segmentation_models.pytorch icon indicating copy to clipboard operation
segmentation_models.pytorch copied to clipboard

preprocessing fn not working

Open rohan-insitro opened this issue 3 years ago • 1 comments

Hello,

I am trying to run the following snippet:

from segmentation_models_pytorch.encoders import get_preprocessing_fn

preprocess_input = get_preprocessing_fn('resnet34', pretrained='imagenet')

for img, mask in trainloader:
    print(x.size())
    x = preprocess_input(x)
    print(x.size())
    break

My images are of shape (3, 64, 64). Batch is (1,3,64,64). But when I try to pass in the tensor into preprocess_input, I get the following error (output from above):

torch.Size([1, 3, 64, 64])
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/ipykernel_88012/1998509273.py in <cell line: 5>()
      5 for img, mask in trainloader:
      6     print(x.size())
----> 7     x = preprocess_input(x)
      8     print(x.size())
      9     break

~/segmentation_models_pytorch/encoders/_preprocessing.py in preprocess_input(x, mean, std, input_space, input_range, **kwargs)
     15     if mean is not None:
     16         mean = np.array(mean)
---> 17         x = x - mean
     18 
     19     if std is not None:

ValueError: operands could not be broadcast together with shapes (1,3,64,64) (3,)  

I am using smp version 0.2.1.

rohan-insitro avatar Aug 07 '22 03:08 rohan-insitro

preprocessing function expect image with shape H, W, C

qubvel avatar Aug 07 '22 20:08 qubvel

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Oct 07 '22 02:10 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Oct 14 '22 02:10 github-actions[bot]