LeeJunHyun / Image_Segmentation

Pytorch implementation of U-Net, R2U-Net, Attention U-Net, and Attention R2U-Net.
2.66k stars 594 forks source link

ValueError: Target and input must have the same number of elements. target nelement (196608) != inpu #66

Closed lenwen-hub closed 1 year ago

lenwen-hub commented 3 years ago

![Uploading 2020-09-28 19-21-19 的屏幕截图.png…]()

lenwen-hub commented 3 years ago

/home/lenwen/PRO_mine/PycharmPRO/UNET/Image_Segmentation-master/venv/bin/python /home/lenwen/PRO_mine/PycharmPRO/UNET/Image_Segmentation-master/main.py Namespace(augmentation_prob=0.43997968647369484, batch_size=1, beta1=0.5, beta2=0.999, cuda_idx=1, image_size=224, img_ch=3, log_step=2, lr=0.00027232275207867595, mode='train', model_path='./models', model_type='U_Net', num_epochs=250, num_epochs_decay=22, num_workers=8, output_ch=1, result_path='./result/U_Net', t=3, test_path='./dataset/test/', train_path='./dataset/train/', val_step=2, valid_path='./dataset/valid/') image count in train path :6000 image count in valid path :2000 image count in test path :2000 /home/lenwen/.local/lib/python3.6/site-packages/torch/nn/functional.py:1625: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead. warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.") /home/lenwen/.local/lib/python3.6/site-packages/torch/nn/modules/loss.py:529: UserWarning: Using a target size (torch.Size([1, 196608])) that is different to the input size (torch.Size([1, 65536])) is deprecated. Please ensure they have the same size. return F.binary_cross_entropy(input, target, weight=self.weight, reduction=self.reduction) Traceback (most recent call last): File "/home/lenwen/PRO_mine/PycharmPRO/UNET/Image_Segmentation-master/main.py", line 101, in main(config) File "/home/lenwen/PRO_mine/PycharmPRO/UNET/Image_Segmentation-master/main.py", line 61, in main solver.train() File "/home/lenwen/PRO_mine/PycharmPRO/UNET/Image_Segmentation-master/solver.py", line 152, in train loss = self.criterion(SR_flat,GT_flat) File "/home/lenwen/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 722, in _call_impl result = self.forward(*input, **kwargs) File "/home/lenwen/.local/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 529, in forward return F.binary_cross_entropy(input, target, weight=self.weight, reduction=self.reduction) File "/home/lenwen/.local/lib/python3.6/site-packages/torch/nn/functional.py", line 2477, in binary_cross_entropy "!= input nelement ({})".format(target.numel(), input.numel())) ValueError: Target and input must have the same number of elements. target nelement (196608) != input nelement (65536)

Process finished with exit code 1

zhkuo24 commented 3 years ago

196608 = 65536 * 3 the value of output_ch is 1, so the channel of GT png should be 1 , not 3

mmlee-web commented 3 years ago

I also have this problem. Have you solved this problem yet? If yes, can you tell me how to solve it? Thanks.