Zyun-Y / DconnNet

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

IndexError: index 112 is out of bounds for dimension 0 with size 50 #7

Closed jamesben6688 closed 8 months ago

jamesben6688 commented 1 year ago

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

Traceback (most recent call last): File "train.py", line 151, in main(args) File "train.py", line 147, in main solver.train(model, train_loader, val_loader,exp_id+1, num_epochs=args.epochs) File "/home/DconnNet/solver.py", line 146, in train loss_main = self.loss_func(output, y) File "/home/.conda/envs/python36/lib/python3.6/site-packages/torch/nn/modules/module.py", line 727, in _call_impl result = self.forward(*input, **kwargs) File "/home/DconnNet/connect_loss.py", line 173, in forward loss = self.multi_class_forward(c_map, target) File "/home/DconnNet/connect_loss.py", line 215, in multi_class_forward dice_l += self.dice_loss(pred[:,j,:,:], onehotmask[:,j],j-1) File "/home/DconnNet/connect_loss.py", line 122, in call b = self.soft_dice_loss(y_true, y_pred,class_i) File "/home/DconnNet/connect_loss.py", line 117, in soft_dice_loss loss = self.soft_dice_coeff(y_true, y_pred,class_i) File "/home/DconnNet/connect_loss.py", line 112, in soft_dice_coeff weight = density_weight(self.bin_wide[class_i], i,self.density[class_i]) File "/home/DconnNet/connect_loss.py", line 141, in density_weight selected_density = [density[index[i].long()] for i in range(gt_cnt.shape[0])] File "/home/DconnNet/connect_loss.py", line 141, in selected_density = [density[index[i].long()] for i in range(gt_cnt.shape[0])] IndexError: index 112 is out of bounds for dimension 0 with size 50

where I am going wrong?

jamesben6688 commented 1 year ago

It seems to be caused by the 'training_positive_pixel_1.npy' file. I guess these npy files record the number of pixels that belong to IRF, SRF, and PED of each 2D slice, respectively. However, the numbers in the npy files are completely different from the mask of the retouch dataset. Could you please let me know if you performed any processing on the mask? Or, if possible, could you share the code for computing these npy files?

Zyun-Y commented 1 year ago

Hi,

Thanks for your interests. Yes, the 'training_positive_pixel_1.npy' records number of pixels of IRF, SRF, and PED. I will check this soon. For now, you can just run without the density loss by simply set 'use_SDL' to False.

I will get you back.

Zyun-Y commented 10 months ago

Thanks for your patience.

The npy files are in the shape of (C, N) where C is the class number, and N is the sample number.

For each cross-validation experiment, we used only the training data to count the pixel distribution.