DmitryUlyanov / deep-image-prior

Image restoration with neural networks but without learning.
https://dmitryulyanov.github.io/deep_image_prior
Other
7.9k stars 1.43k forks source link

ValueError: operands could not be broadcast together with shapes #79

Closed avmiz closed 4 years ago

avmiz commented 4 years ago

ValueError Traceback (most recent call last)

in () 1 img_mask_var = np_to_torch(img_mask_np).type(dtype) 2 ----> 3 plot_image_grid([img_np, img_mask_np, img_mask_np*img_np], 3,11); ValueError: operands could not be broadcast together with shapes (4,320,320) (3,320,320) I have that strange error, does anyone know how to fix it?
orgrinrt commented 4 years ago

Looks like one of the input images has 4 channels and the other 3. I suspect you're using alpha channel for the mask?

(4,320,320) (3,320,320)

I assume the program expects the inputs to have similar signature, so it's easy enough to fix. Provide either two 3-channel or two 4-channel inputs (i.e either with alpha channel or not). Or you could skip this altogether by disabling plotting I think, but not sure what that would mean for the program and results. Or, modify the source to work with your use case. For one, you could simply make it translate all pixels with alpha<threshold to white and remove the channel, so you needn't worry about the image signatures and can just do your thing.

I tested this and was able to reproduce this exact error by mixing images with alpha channel and no alpha channel as input. Providing matching images always fixed the problem. So I think this is the case here too. You probably figured this out by now because it's fairly obvious, but I thought to stop by and throw a comment in case someone else happens to have similar problem.

Of course it could be any number of other things, I'm not that familiar with the source, but at least this is one scenario in which this error happens, so it's worth a shot at the very least.

avmiz commented 4 years ago

You are right, i've solved the problem, and yes, it was the alpha channel, so the easiest solution is delete it