segmentation_models.pytorch
segmentation_models.pytorch copied to clipboard
preprocessing fn not working
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.
preprocessing function expect image with shape H, W, C
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.
This issue was closed because it has been stalled for 7 days with no activity.