cosmic-cortex / pytorch-UNet

2D and 3D UNet implementation in PyTorch.
MIT License
147 stars 40 forks source link

RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of size: : [1, 512, 512, 3] #11

Open Shrutika994 opened 4 years ago

Shrutika994 commented 4 years ago

Hello please kindly look at this error. Whenever I try to train my dataset by using train.py I keep getting this error. As I am new to pytorch a little guidance would be helpful. RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of size: : [1, 512, 512, 3]

Thank you in advance.

cosmic-cortex commented 4 years ago

Hi!

Can you post the full stack trace? I cannot really say anything with this information only.

Shrutika994 commented 4 years ago

Hi!

Traceback (most recent call last): File "train.py", line 60, in metric_list=metric_list, verbose=True) File "/home/shrutika/pytorch-UNet-master/pytorch-UNet-master/unet/model.py", line 186, in fit_dataset train_logs = self.fit_epoch(dataset, n_batch=n_batch, shuffle=shuffle) File "/home/shrutika/pytorch-UNet-master/pytorch-UNet-master/unet/model.py", line 99, in fit_epoch training_loss = self.loss(y_out, y_batch) File "/home/shrutika/anaconda3/envs/3dunet/lib/python3.7/site-packages/torch/nn/modules/module.py", line 532, in call result = self.forward(*input, **kwargs) File "/home/shrutika/pytorch-UNet-master/pytorch-UNet-master/unet/metrics.py", line 20, in forward ignore_index=self.ignore_index) File "/home/shrutika/anaconda3/envs/3dunet/lib/python3.7/site-packages/torch/nn/functional.py", line 2021, in cross_entropy return nll_loss(log_softmax(input, 1), target, weight, None, ignore_index, None, reduction) File "/home/shrutika/anaconda3/envs/3dunet/lib/python3.7/site-packages/torch/nn/functional.py", line 1840, in nll_loss ret = torch._C._nn.nll_loss2d(input, target, weight, _Reduction.get_enum(reduction), ignore_index) RuntimeError: 1only batches of spatial targets supported (non-empty 3D tensors) but got targets of size: : [1, 512, 512, 3]