jeya-maria-jose / UNeXt-pytorch

Official Pytorch Code base for "UNeXt: MLP-based Rapid Medical Image Segmentation Network", MICCAI 2022
https://jeya-maria-jose.github.io/UNext-web/
MIT License
459 stars 76 forks source link

deep_supervision #7

Closed long123524 closed 1 year ago

long123524 commented 2 years ago

image I want to use deep_supervision, but I find a error, should I how to deal with this error? What the function of the deep_supervision? Thank you!

Zhu1Li commented 2 years ago

I finished the training on BUSI without DS, but when I tried to train on BUSI dataset with DS and met the same question, have you solved it? @long123524

Zhu1Li commented 2 years ago

I finished the training on BUSI without DS, but when I tried to train on BUSI dataset with DS and met the same question, have you solved it? @long123524

Hey I got where the problem is, it happens because your "output"(torch.Size([1, 256, 256])) and "target"( torch.Size([8, 1, 256, 256])) is not dimmensional equal so your criterion function cannot calculate the right loss, all you need to do is changing the

for output in outputs:

loss += criterion(output, target)

into

for i in range(len(outputs)):

loss += criterion(outputs[i], target[i])

in both train function(119,120 line) and validate function(166, 167 line) of train.py; then the code with configure "--deep_supervision True" will run correctly.

Zhu1Li commented 2 years ago

I finished the training on BUSI without DS, but when I tried to train on BUSI dataset with DS and met the same question, have you solved it? @long123524

Hey I got where the problem is, it happens because your "output"(torch.Size([1, 256, 256])) and "target"( torch.Size([8, 1, 256, 256])) is not dimmensional equal so your criterion function cannot calculate the right loss, all you need to do is changing the

for output in outputs:

loss += criterion(output, target)

into

for i in range(len(outputs)):

loss += criterion(outputs[i], target[i])

in both train function(119,120 line) and validate function(166, 167 line) of train.py; then the code with configure "--deep_supervision True" will run correctly.

Found something wrong with code, I used same configures but got a very terrible IoU score on BUSI dataset with deep supervision than without, and I compared the code of UNeXt and UNet++, found that archs.py of UNeXt which defines the network architecture considers nothing about deep supervision(just one stage to output), while the losses.py and the part of train&vaildate function about deep supervision in train.py is totally the same as UNet++'s code. So I guess that the author did not consider using deep supervision in the network, but just modified the code framework against UNet++ without removing the deep supervision part.

jeya-maria-jose commented 1 year ago

Yes, deep supervision part was not used in UNeXt training.

Alan-Py commented 1 year ago

I finished the training on BUSI without DS, but when I tried to train on BUSI dataset with DS and met the same question, have you solved it? @long123524

Hey I got where the problem is, it happens because your "output"(torch.Size([1, 256, 256])) and "target"( torch.Size([8, 1, 256, 256])) is not dimmensional equal so your criterion function cannot calculate the right loss, all you need to do is changing the

for output in outputs:

loss += criterion(output, target)

into

for i in range(len(outputs)):

loss += criterion(outputs[i], target[i])

in both train function(119,120 line) and validate function(166, 167 line) of train.py; then the code with configure "--deep_supervision True" will run correctly.

Good job