bigmb / Unet-Segmentation-Pytorch-Nest-of-Unets

Implementation of different kinds of Unet Models for Image Segmentation - Unet , RCNN-Unet, Attention Unet, RCNN-Attention Unet, Nested Unet
MIT License
1.87k stars 345 forks source link

TypeError: function takes exactly 1 argument (3 given) #28

Closed yuheng222 closed 4 years ago

yuheng222 commented 4 years ago

Hi there,

I'm relatively new to medical image segmentation and I want to use your models to experiment on some CT/MRI images and labels in NIFTI (.nii.gz) format.

I converted the 3D NIFTI images and labels to 2D images in .png format using your 2d_from_3rd.py script, but after running pytorch_run.py, I was faced with the following error:

Screenshot from 2020-02-10 16-11-24

May I know what might be the cause of this error? Thanks!

yuheng222 commented 4 years ago

Solved by downgrading torch from 1.4.0 to 1.3.1, torchvision from 0.5.0 to 0.4.2, pillow from 7.0.0 to 6.2.1.

bigmb commented 4 years ago

I think this was caused by torch1.4.0 and its compatibility with PIL image.

yuheng222 commented 4 years ago

Yes, I think so too. Thanks for the reply!

Just another question, if I would like to train my model with multiclass dataset, which lines do I have to change? I tried changing all the sigmoid in pytorch_run.py to softmax but it didnt work since the dice score is still low. Thanks.

bigmb commented 4 years ago

Did you change the input and output for the model? And by changing the to softmax it should work. What's the dice score?

yuheng222 commented 4 years ago

The dice score is 0.23958333333333334.

For the input shape, I tried changing the line: model_test = model_unet(model_Inputs[0], 3, 1) to model_test = model_unet(model_Inputs[0], 3, 8) since my there are 8 classes in my dataset labels but I get this error: ValueError: Target size (torch.Size([4, 1, 96, 96])) must be the same as input size (torch.Size([4, 8, 96, 96])). Where can I change the shape of the model output? I can't seem to find the line to change output shape in pytorch_run.py. Thank you for helping!

bigmb commented 4 years ago

Dice score = 0.24 is not good at all. Yes by changing it to (model_input[0],3,8 ) it should be working for 8 classes.

Also, you have to change it to softmax to make it work for all prediction line. pred_tb = F.sigmoid(pred_tb)

Can you tell me which line you are facing this issue?