DmitryUlyanov / deep-image-prior

Image restoration with neural networks but without learning.

Home Page:https://dmitryulyanov.github.io/deep_image_prior

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ValueError: operands could not be broadcast together with shapes

avmiz opened this issue · comments

commented

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?

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.

commented

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