Using a target size that is different to the input size is deprecated. Please ensure they have the same size

Hi, Doing Background Removal With U2net.
The error i’m getting is :

Using a target size (torch.Size([5, 3, 320, 320])) that is different to the input size (torch.Size([5, 1, 320, 320])) is deprecated. Please ensure they have the same size.

As you may know, This is a Segmentation Type task. so, it has RGB Image as X and Ground Truth Grayscale Image as Y.

The error is when i apply this model output to Loss Function. I’m Using BCE Loss.

What should i do? i don’t want to debug that error by just converting input image to Grayscale.
is there any other way ?

Thanks in advance.

your input size is (5,1,320,320) the model is expecting to have (5,3,320,320).

If you don’t want to pass RGB images

you can change
Conv2d(3,-,(-,-)) to Conv2d(1,-,(-,-))

if you are using a linear layer you can change

Linear(3*320*320,-) to Linear(1*320*320)

Hope this helps

With best regards,
Ranuga

1 Like

And also I have seen this more in BCELoss (In my personal Projects)

I am not sure if it has anything to do with BCELoss.

Hi,

Thanks for your reply.

What you have said make sense in spite of the model but the problem was in processing the image Data. I could have explained that extensively.

Again, Thanks for the reply.

1 Like