Yanfeng-Zhou / XNet

[ICCV2023] XNet: Wavelet-Based Low and High Frequency Merging Networks for Semi- and Supervised Semantic Segmentation of Biomedical Images
MIT License
186 stars 9 forks source link

The size of tensor a (16384) must match the size of tensor b (49152) at non-singleton dimension 1 #25

Open HHDAW opened 2 months ago

HHDAW commented 2 months ago

Hello,thanks for your great work.I had some problems before the model training started.I tried to adjust the image but it didn't work.Please give me some advice.The following is the error message Traceback (most recent call last): File "/root/autodl-tmp/XNET/XNet-main/XNet-main/train_semi_XNet.py", line 254, in loss_train_sup1 = criterion(pred_train_sup1, mask_train_sup) File "/root/miniconda3/envs/xnet3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(*input, *kwargs) File "/root/autodl-tmp/XNET/XNet-main/XNet-main/loss/loss_function.py", line 119, in forward return self._base_forward(output, target_one_hot, valid_mask) File "/root/autodl-tmp/XNET/XNet-main/XNet-main/loss/loss_function.py", line 92, in _base_forward dice_loss = dice(predict[:, i], target[..., i], valid_mask) File "/root/miniconda3/envs/xnet3/lib/python3.8/site-packages/torch/nn/modules/module.py", line 889, in _call_impl result = self.forward(input, *kwargs) File "/root/autodl-tmp/XNET/XNet-main/XNet-main/loss/loss_function.py", line 59, in forward num = torch.sum(torch.mul(predict, target) valid_mask, dim=1) * 2 + self.smooth RuntimeError: The size of tensor a (16384) must match the size of tensor b (49152) at non-singleton dimension 1

Yanfeng-Zhou commented 2 months ago

This error is caused by the inconsistency between image size and mask size.

HHDAW commented 2 months ago

Yes.I read the previous question.But I use the /config/augmentation/online_aug.py to resize the image,it still reports errors.

Yanfeng-Zhou commented 2 months ago

Can you print pred_train_sup1.shape and mask_train_sup.shape. There are some problems with the first dimension of these two tensors.

HHDAW commented 2 months ago

pred_train_sup1.shape([2, 2, 128, 128]) and mask_train_sup.shape ([2, 128, 128, 3, 256])

Yanfeng-Zhou commented 2 months ago

The shape of your mask is very strange. Generally speaking, for 2D images, the image shape is [B, C, H, W] while the mask shape is [B, H, W]. what is the meaning of "3" and "256" in your mask shape.

HHDAW commented 1 month ago

Sorry,I have one more question to ask. During training,Why is my best printed data inconsistent with my saved model.Saved results are less than optimal