pytorch-msssim icon indicating copy to clipboard operation
pytorch-msssim copied to clipboard

When I wanna deal with grayscale image,it report this problem

Open WYCAS opened this issue 3 years ago • 4 comments

When I input 2D grayscale image ,i report this. ValueError: Input images should be 4-d or 5-d tensors, but got torch.Size([256, 256])

Therefore,I change the input dimension to 4D(1,1,256,256),but i got this problem. RuntimeError: Given groups=1, weight of size [3, 1, 1, 11], expected input[1, 3, 246, 256] to have 1 channels, but got 3 channels instead

WYCAS avatar Oct 18 '21 08:10 WYCAS

Hi @WYCAS , it seems that the input tensor was a RGB image. Could you provide more detials, such as a minimal example to produce this error?

VainF avatar Oct 19 '21 08:10 VainF

Input :a = torch.randint(0, 255, size=( 256, 256), dtype=torch.float32).cuda() / 255. b = a * 0.5 ValueError: Input images should be 4-d or 5-d tensors, but got torch.Size([256, 256])

Input:a = torch.randint(0, 255, size=(1,1,256, 256), dtype=torch.float32).cuda() / 255. b = a * 0.5 RuntimeError: Given groups=1, weight of size [3, 1, 1, 11], expected input[1, 3, 246, 256] to have 1 channels, but got 3 channels instead

Do I have to change the grayscale image to RGB image? By the way ,when I use pytorch-msssim=0.1,it can work on grayscale image

WYCAS avatar Oct 20 '21 02:10 WYCAS

The ssim metric worked well on my laptop. Maybe the parameter channel was missing in your code?

ssim = SSIM(data_range=1., channel=1)

VainF avatar Oct 20 '21 05:10 VainF

thanks , It works!

WYCAS avatar Oct 21 '21 02:10 WYCAS