Zyun-Y / DconnNet

Codes for CVPR2023 paper "Directional Connectivity-based Segmentation of Medical Images"
131 stars 7 forks source link

RuntimeError: permute(sparse_coo): number of dimensions in the tensor input does not match the length of the desired ordering of dimensions i.e. input.dim() = 5 is not equal to len(dims) = 4 #9

Closed lgc-china closed 1 year ago

lgc-china commented 1 year ago

When I run the train.py on ReTouch dataset, I got the following error:

/anaconda3/envs/pt1130cu117py39/lib/python3.9/site-packages/apex-0.1-py3.9.egg/apex/init.py:68: DeprecatedFeatureWarning: apex.amp is deprecated and will be removed by the end of February 2023. Use PyTorch AMP /anaconda3/envs/pt1130cu117py39/lib/python3.9/site-packages/torch/nn/functional.py:1967: UserWarning: nn.functional.sigmoid is deprecated. Use torch.sigmoid instead. warnings.warn("nn.functional.sigmoid is deprecated. Use torch.sigmoid instead.") Traceback (most recent call last): File "/home/lgc/pycharm_code/DconnNet-main/train.py", line 151, in main(args) File "/home/lgc/pycharm_code/DconnNet-main/train.py", line 147, in main solver.train(model, train_loader, val_loader,exp_id+1, num_epochs=args.epochs) File "/home/lgc/pycharm_code/DconnNet-main/solver.py", line 147, in train loss_main = self.loss_func(output, y) File "/anaconda3/envs/pt1130cu117py39/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1190, in _call_impl return forward_call(*input, **kwargs) File "/home/lgc/pycharm_code/DconnNet-main/connect_loss.py", line 172, in forward loss = self.multi_class_forward(c_map, target) File "/home/lgc/pycharm_code/DconnNet-main/connect_loss.py", line 185, in multi_class_forward onehotmask = onehotmask.permute(0,3,1,2) RuntimeError: permute(sparse_coo): number of dimensions in the tensor input does not match the length of the desired ordering of dimensions i.e. input.dim() = 5 is not equal to len(dims) = 4

Zyun-Y commented 1 year ago

Hi,

It looks like to be your target shape/class number issue. Please check the shape of your target. Make sure it to be (B, H, W). Please also check the class number you used in F.one_hot is correct by changing onehotmask = F.one_hot(target.long(),4) to be onehotmask = F.one_hot(target.long(),Your class number)

For further issue, please refer to the official documentation of one_hot function in Pytorch.

lgc-china commented 1 year ago

Thank you very much for your answer

------------------ 原始邮件 ------------------ 发件人: "Zyun-Y/DconnNet" @.>; 发送时间: 2023年6月20日(星期二) 凌晨1:41 @.>; @.**@.>; 主题: Re: [Zyun-Y/DconnNet] RuntimeError: permute(sparse_coo): number of dimensions in the tensor input does not match the length of the desired ordering of dimensions i.e. input.dim() = 5 is not equal to len(dims) = 4 (Issue #9)

Hi,

It looks like to be your target shape/class number issue. Please check the shape of your target. Make sure it to be (B, H, W). Please also check the class number you used in F.one_hot is correct by changing onehotmask = F.one_hot(target.long(),4) to be onehotmask = F.one_hot(target.long(),Your class number)

For further issue, please refer to the official documentation of one_hot function in Pytorch.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>