Zyun-Y / DconnNet

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

What is the details of training on dataset ISIC2018? #11

Closed 16rq closed 1 year ago

16rq commented 1 year ago

I want to study deeper and better of your paper via code. And I choose dataset ISIC2018 you provide. But I met the error as follows. Some dimension error. So I wonder if you could provide us with the details of training o ISIC2018 like you did on other datasets? I would appreciate a lot.


Traceback (most recent call last): File "../DconnNet/train.py", line 156, in main(args) File ../DconnNet/train.py", line 148, in main solver.train(model, train_loader, val_loader,exp_id+1, num_epochs=args.epochs) File "../DconnNet/solver.py", line 147, in train loss_main = self.loss_func(output, y) File "../anaconda3/envs/Dcon/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl return forward_call(*input, **kwargs) File "../DconnNet/connect_loss.py", line 172, in forward loss = self.multi_class_forward(c_map, target) File "../DconnNet/connect_loss.py", line 184, 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

wzh0328 commented 1 year ago

Hello, have you solved this problem?

Zyun-Y commented 1 year ago

Hi, I noticed that you are using a multi-class loss function for the ISIC dataset here. Please note that ISIC2018 is a single-class segmentation task so please make sure you set the correct class number in the code.

If the issue is not solved by changing the class number, please refer to #9.

wzh0328 commented 1 year ago

Sorry, I set num-class to 1, but I still get an error. RuntimeError: Expected size for first two dimensions of batch2 tensor to be: [4, 320] but got: [36, 320].

wzh0328 commented 1 year ago

Hi, I noticed that you are using a multi-class loss function for the ISIC dataset here. Please note that ISIC2018 is a single-class segmentation task so please make sure you set the correct class number in the code.

If the issue is not solved by changing the class number, please refer to #9.

Does the isic data set have the same sh file as the other data sets?

Zyun-Y commented 1 year ago

Could you give a detailed description of where did this bug happen?

wzh0328 commented 1 year ago

Could you give a detailed description of where did this bug happen?

Traceback (most recent call last): File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/train.py", line 153, in main(args) File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/train.py", line 149, in main solver.train(model, train_loader, val_loader,exp_id+1, num_epochs=args.epochs) File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/solver.py", line 147, in train loss_main = self.loss_func(output, y) File "/root/miniconda3/envs/wzh/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/connect_loss.py", line 174, in forward loss = self.single_class_forward(c_map, target) File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/connect_loss.py", line 261, in single_class_forward pred,bicon_map = Bilateral_voting(class_pred,hori_translation,verti_translation) File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/connect_loss.py", line 68, in Bilateral_voting right = (torch.bmm(c_map[:,:,4].contiguous().view(-1,row,column),hori_translation.view(-1,column,column))).view(batch,class_num,row,column) RuntimeError: Expected size for first two dimensions of batch2 tensor to be: [4, 320] but got: [36, 320].

Process finished with exit code 1 This is my error. I try to print out the shape of the output out and the result is [4,8,224,320].Thank you!

Zyun-Y commented 1 year ago

Hi, I noticed that you are using a multi-class loss function for the ISIC dataset here. Please note that ISIC2018 is a single-class segmentation task so please make sure you set the correct class number in the code. If the issue is not solved by changing the class number, please refer to #9.

Does the isic data set have the same sh file as the other data sets?

As we mentioned in this repository, we used the framework of this code to train the ISIC for a fair comparison. Therefore, unfortunately, there is no .sh file for ISIC in this repository.

However, we can provide the hyperparameters and a training guide that we used to train the ISIC later in this post for further reproductivity.

Zyun-Y commented 1 year ago

Could you give a detailed description of where did this bug happen?

Traceback (most recent call last): File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/train.py", line 153, in main(args) File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/train.py", line 149, in main solver.train(model, train_loader, val_loader,exp_id+1, num_epochs=args.epochs) File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/solver.py", line 147, in train loss_main = self.loss_func(output, y) File "/root/miniconda3/envs/wzh/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1110, in _call_impl return forward_call(*input, **kwargs) File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/connect_loss.py", line 174, in forward loss = self.single_class_forward(c_map, target) File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/connect_loss.py", line 261, in single_class_forward pred,bicon_map = Bilateral_voting(class_pred,hori_translation,verti_translation) File "/root/autodl-tmp/wzh/DconnNet-main/DconnNet-main/connect_loss.py", line 68, in Bilateral_voting right = (torch.bmm(c_map[:,:,4].contiguous().view(-1,row,column),hori_translation.view(-1,column,column))).view(batch,class_num,row,column) RuntimeError: Expected size for first two dimensions of batch2 tensor to be: [4, 320] but got: [36, 320].

Process finished with exit code 1 This is my error. I try to print out the shape of the output out and the result is [4,8,224,320].Thank you!

Thanks. Would you mind also sharing your inputs' shape for Bilateral_voting? I.e., shapes of class_pred, hori_translation, verti_translation. Could you check if they meet the shape requirement in the codes? You can find the requirement in line 225 to 253 connect_loss.py:

    ### get your connectivity_mask ###
    con_target = connectivity_matrix(target,self.args.num_class)#(B, 8, H, W)

    ### matrix for shifting
    hori_translation = self.hori_translation.repeat(batch_num,1,1,1).cuda()
    verti_translation = self.verti_translation.repeat(batch_num,1,1,1).cuda()

    c_map = F.sigmoid(c_map)

    ### get edges gt###
    class_conn = con_target.view([c_map.shape[0],self.args.num_class,8,c_map.shape[2],c_map.shape[3]])
    sum_conn = torch.sum(class_conn,dim=2)

    ## edge: (B, 1, H, W)
    edge = torch.where((sum_conn<8) & (sum_conn>0),torch.full_like(sum_conn, 1),torch.full_like(sum_conn, 0))

    ### bilateral voting #####
    ## pred: (B, 1, H, W), bicon_map: (B, 1, 8, H, W)
    class_pred = c_map.view([c_map.shape[0],self.args.num_class, 8, c_map.shape[2],c_map.shape[3]])
    pred,bicon_map = Bilateral_voting(class_pred,hori_translation,verti_translation)`
wzh0328 commented 1 year ago

hori_translation

The shape of class_pred is: torch.Size([4, 1, 8, 224, 320]) The shape of hori_translation is :torch.Size([4, 1, 960, 960]) The shape of verti_translation is:torch.Size([4, 1, 960, 960])

Zyun-Y commented 1 year ago

hori_translation

The shape of class_pred is: torch.Size([4, 1, 8, 224, 320]) The shape of hori_translation is :torch.Size([4, 1, 960, 960]) The shape of verti_translation is:torch.Size([4, 1, 960, 960])

I see. So the problem is you didn't set the correct shape for hori_translation and verti_translation. The shape of hori_translation should be [Batch, NumClass, W, W] and for verti_translation it should be [Batch, NumClass, H, H] (please check line 28 - 35 in solver.py) as their function is to translate the map to different directions. You can simply correct it by passing [224, 320] to the args.resize in train.py.

Hope this helps.

wzh0328 commented 1 year ago

hori_translation

The shape of class_pred is: torch.Size([4, 1, 8, 224, 320]) The shape of hori_translation is :torch.Size([4, 1, 960, 960]) The shape of verti_translation is:torch.Size([4, 1, 960, 960])

I see. So the problem is you didn't set the correct shape for hori_translation and verti_translation. The shape of hori_translation should be [Batch, NumClass, W, W] and for verti_translation it should be [Batch, NumClass, H, H] (please check line 28 - 35 in solver.py) as their function is to translate the map to different directions. You can simply correct it by passing [224, 320] to the args.resize in train.py.

Hope this helps.

Well, thank you very much for your answer.

wzh0328 commented 1 year ago

这是来自QQ邮箱的假期自动回复邮件。您好,您的邮箱我已收到,谢谢合作

LYC123080 commented 2 months ago

Excuse me,I download the ISIC you provided and then I set num-class to 1,but but I still get an error RuntimeError: Class values must be smaller than num_classes. The details are as follows Traceback (most recent call last): File "G:\code\DconnNet-main\train.py", line 154, in main(args) File "G:\code\DconnNet-main\train.py", line 150, in main solver.train(model, train_loader, val_loader,exp_id+1, num_epochs=args.epochs) File "G:\code\DconnNet-main\solver.py", line 147, in train loss_main = self.loss_func(output, y) File "G:\soft\Ano\envs\test1\lib\site-packages\torch\nn\modules\module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "G:\code\DconnNet-main\connect_loss.py", line 172, in forward loss = self.multi_class_forward(c_map, target) File "G:\code\DconnNet-main\connect_loss.py", line 187, in multi_class_forward onehotmask = F.one_hot(target.long(),1) # change it to your class number if needed RuntimeError: Class values must be smaller than num_classes.

LYC123080 commented 2 months ago

I want to study deeper and better of your paper via code. And I choose dataset ISIC2018 you provide. But I met the error as follows. Some dimension error. So I wonder if you could provide us with the details of training o ISIC2018 like you did on other datasets? I would appreciate a lot.

Traceback (most recent call last): File "../DconnNet/train.py", line 156, in main(args) File ../DconnNet/train.py", line 148, in main solver.train(model, train_loader, val_loader,exp_id+1, num_epochs=args.epochs) File "../DconnNet/solver.py", line 147, in train loss_main = self.loss_func(output, y) File "../anaconda3/envs/Dcon/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1194, in _call_impl return forward_call(*input, **kwargs) File "../DconnNet/connect_loss.py", line 172, in forward loss = self.multi_class_forward(c_map, target) File "../DconnNet/connect_loss.py", line 184, 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

Can I ask what changes I need to make to the source code if I use the ISIC database?