chvlyl / ISIC2018

Lesion attributes segmentation for melanoma detection with multi-task U-Net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error while train

glcanvas opened this issue · comments

Hi!
I got error while launch train.py script

Traceback (most recent call last):
  File "train.py", line 394, in <module>
    main()
  File "train.py", line 323, in main
    loss2 = F.binary_cross_entropy_with_logits(outputs_mask_ind1, train_mask_ind)
  File "/nfs/home/nduginets/miniconda3/envs/with_torch/lib/python3.7/site-packages/torch/nn/functional.py", line 2980, in binary_cross_entropy_with_logits
    raise ValueError("Target size ({}) must be the same as input size ({})".format(target.size(), input.size()))
ValueError: Target size (torch.Size([4, 5])) must be the same as input size (torch.Size([20]))

my command

python3 train.py --checkpoint isic_2018_checkpoint/1_multi_task_unet      
--train-test-split-file /nfs/home/nduginets/ISIC2018/data/train_test_id.pickle         
--image-path /mnt/tank/scratch/nduginets/task2_h5/  
--batch-size 4```

I think the error message is self-explained. Your label shape [20] doesn't look right. It should be [4,5]. 4 is the batch size and 5 is the 5-class vector. You can either reshape your label or flatten your model prediction

yes, I know that's self-explained
but this is your code=)
I launched it without any modification

OK, thanks for reporting this issue. I will look into it.

you may fix it in 2 lines =)

        x_out_empty_ind1 = torch.squeeze(x_out_empty_ind1)
        x_out_empty_ind1 = torch.reshape(x_out_empty_ind1, (1, x_out_empty_ind1.shape[0]))

same for x_out_empty_ind2