Pytorch-UNet icon indicating copy to clipboard operation
Pytorch-UNet copied to clipboard

n_classes and Target size

Open petksand opened this issue 3 years ago • 2 comments

Hi,

I'm training on a dataset with 1 class and a background. My masks are formatted with [0,1]. However, when I run train.py with n_classes=1, I get the error: Target 1 is out of bounds.

When training with n_classes=2, all the output images are black. Is there a different way the masks should be formatted?

Thanks.

petksand avatar Nov 25 '21 16:11 petksand

n_classes=2 with 0/1 targets should work. Where do you see the black images, in wandb or when running the predict script? Also, how long did you train the network for?

milesial avatar Nov 25 '21 22:11 milesial

I want to know the label of the background,0/1 is multi label

Devictor0815 avatar Mar 31 '22 07:03 Devictor0815

In Binary problem , which like [0,1] case, u have to set "n_classes=2", not 1

LimSeJin9577 avatar Oct 25 '22 03:10 LimSeJin9577

Hello @milesial. Please reopen this issue as I am facing the exact same problem. Setting --classes flag to 2 results in 0,1,2 values when running the prediction script using trained weights. It should only be resulting in 0,1 for binary segmentation. Am I missing something here? I trained my model for around 100 epochs.

ZeeRizvee avatar Oct 26 '23 21:10 ZeeRizvee