Giter Site home page Giter Site logo

Comments (13)

bigmb avatar bigmb commented on July 16, 2024

It's because of your input size.
If possible change it to 256X256. Should be divisible by 2, according to the depth of the model.

from unet-segmentation-pytorch-nest-of-unets.

Y-P-W avatar Y-P-W commented on July 16, 2024

I tried it, but it's still an error. I feel that maybe my data is wrong. Can you describe your data, such as the size and depth of the image of training and labeled data? I'd like to use this project to try the segmentation of arteries and veins. Can you give me some suggestions on how to modify the program to suit my project,thanks!

from unet-segmentation-pytorch-nest-of-unets.

Y-P-W avatar Y-P-W commented on July 16, 2024

And when my label images are 1 channel, I get the following error.
Traceback (most recent call last):
File "/home/pharos/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3325, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
runfile('/home/pharos/Pharos/Program/Att_U-Net/Unet-Segmentation-Pytorch-Nest-of-Unets-master/pytorch_run.py', wdir='/home/pharos/Pharos/Program/Att_U-Net/Unet-Segmentation-Pytorch-Nest-of-Unets-master')
File "/home/pharos/Pharos/Download/pycharm-community-anaconda-2019.2.3/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/home/pharos/Pharos/Download/pycharm-community-anaconda-2019.2.3/helpers/pydev/pydev_imps/pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/pharos/Pharos/Program/Att_U-Net/Unet-Segmentation-Pytorch-Nest-of-Unets-master/pytorch_run.py", line 295, in
s_label = data_transform(im_label)
File "/home/pharos/anaconda3/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 61, in call
img = t(img)
File "/home/pharos/anaconda3/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 166, in call
return F.normalize(tensor, self.mean, self.std, self.inplace)
File "/home/pharos/anaconda3/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 217, in normalize
tensor.sub
(mean[:, None, None]).div
(std[:, None, None])
RuntimeError: output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256]

from unet-segmentation-pytorch-nest-of-unets.

bigmb avatar bigmb commented on July 16, 2024

So, my data was variable. (it was 3x256x256 , 3x128x128, 3x64x64)
Label data was single channel. depending upon the input i am using.

is it a binary segmentation or multi segmentation? if it's multi then you need to change it to softmax function.

from unet-segmentation-pytorch-nest-of-unets.

Y-P-W avatar Y-P-W commented on July 16, 2024

I want to do binary segmentation of blood vessel first, and do the multi segmentation in the modified model.
when i used train image(3x256x256) and label image(1x256x256) in Attention U-Net, I still have the following error. "IndexError: tuple index out of range"
And i fixed the second error " RuntimeError" by Normalize the training data without testing data,But I don't quite understand why.
please guide!thanks

from unet-segmentation-pytorch-nest-of-unets.

bigmb avatar bigmb commented on July 16, 2024

In attention unet, can you tell me where the error is?
Is it at x4?
Does it run for other models?

If its binary segmentation then the code should run perfectly.

from unet-segmentation-pytorch-nest-of-unets.

Y-P-W avatar Y-P-W commented on July 16, 2024

Errors occur in the Attention unet and R2AttU_Net. Others U-Net run perfectly after i fixed the second error " RuntimeError" .

Traceback (most recent call last):
File "/home/pharos/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3325, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
runfile('/home/pharos/Pharos/Program/Att_U-Net/Unet-Segmentation-Pytorch-Nest-of-Unets-master/pytorch_run.py', wdir='/home/pharos/Pharos/Program/Att_U-Net/Unet-Segmentation-Pytorch-Nest-of-Unets-master')
File "/home/pharos/Pharos/Download/pycharm-community-anaconda-2019.2.3/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/home/pharos/Pharos/Download/pycharm-community-anaconda-2019.2.3/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/pharos/Pharos/Program/Att_U-Net/Unet-Segmentation-Pytorch-Nest-of-Unets-master/pytorch_run.py", line 100, in
torchsummary.summary(model_test, input_size=(3, 256, 256))
File "/home/pharos/anaconda3/lib/python3.7/site-packages/torchsummary/torchsummary.py", line 72, in summary
model(*x)
File "/home/pharos/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 541, in call
result = self.forward(*input, **kwargs)
File "/home/pharos/Pharos/Program/Att_U-Net/Unet-Segmentation-Pytorch-Nest-of-Unets-master/Models.py", line 349, in forward
x4 = self.Att5(g=d5, x=e4)
File "/home/pharos/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 543, in call
hook_result = hook(self, input, result)
File "/home/pharos/anaconda3/lib/python3.7/site-packages/torchsummary/torchsummary.py", line 19, in hook
summary[m_key]["input_shape"] = list(input[0].size())
IndexError: tuple index out of range

please , thanks!

from unet-segmentation-pytorch-nest-of-unets.

bigmb avatar bigmb commented on July 16, 2024

comment torchsummary.
It has this issue. Run without that and let me know if that works.

I have had that problem and I had upgraded pytorch to 1.1.0 and still had this issue.

from unet-segmentation-pytorch-nest-of-unets.

Y-P-W avatar Y-P-W commented on July 16, 2024

thanks for your replied! It can work without torchsummary.
But as i mentioned above, I had modified data_transform (line 121th) to solve the following problem.
I checked the meaning of mean and std in torchvision.transforms.Normalize, mean: (M1,...,Mn) and std: (S1,..,Sn) for n channels. I think the error is because the normalization cannot be used on the label image[256 x 256].
To solve this problem, i commented "torchvision.transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])"(line 125th).
And i added two lines of code at line 297th and 298th.
Norm = torchvision.transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5]) s_tb = Norm(s_tb)
Do you think it is right? Do i need to normalize the test label image?

Error:
Traceback (most recent call last):
File "/home/pharos/anaconda3/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3325, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in
runfile('/home/pharos/Pharos/Program/Att_U-Net/Unet-Segmentation-Pytorch-Nest-of-Unets-master/pytorch_run.py', wdir='/home/pharos/Pharos/Program/Att_U-Net/Unet-Segmentation-Pytorch-Nest-of-Unets-master')
File "/home/pharos/Pharos/Download/pycharm-community-anaconda-2019.2.3/helpers/pydev/_pydev_bundle/pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "/home/pharos/Pharos/Download/pycharm-community-anaconda-2019.2.3/helpers/pydev/pydev_imps/pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/home/pharos/Pharos/Program/Att_U-Net/Unet-Segmentation-Pytorch-Nest-of-Unets-master/pytorch_run.py", line 295, in
s_label = data_transform(im_label)
File "/home/pharos/anaconda3/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 61, in call
img = t(img)
File "/home/pharos/anaconda3/lib/python3.7/site-packages/torchvision/transforms/transforms.py", line 166, in call
return F.normalize(tensor, self.mean, self.std, self.inplace)
File "/home/pharos/anaconda3/lib/python3.7/site-packages/torchvision/transforms/functional.py", line 217, in normalize
tensor.sub(mean[:, None, None]).div(std[:, None, None])
RuntimeError: output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256]

from unet-segmentation-pytorch-nest-of-unets.

bigmb avatar bigmb commented on July 16, 2024

if you normalize the test dataset it should be single-channel (it is grayscale right?)
torchvision.transforms.Normalize(mean=[0.5], std=[0.5])
try this.

from unet-segmentation-pytorch-nest-of-unets.

Y-P-W avatar Y-P-W commented on July 16, 2024

ok, but I have some question. Can you explain the meaning of output channel to me? it is the number of class? why its value is 1 in binary segmentation? If my class (including background) are 3, what is its value?
if i change sigmoid to softmax, do the sigmoid in the attention block need to be modified?
thanks!

from unet-segmentation-pytorch-nest-of-unets.

bigmb avatar bigmb commented on July 16, 2024

Out channel - Classes.
if you have 3 classes then it will be 3.

In binary it is 1 , because it just has to find one class and make the rest of the pixels blank. You can make it 2 , but then you have to edit it in how the values will be classified. Just to avoid that classification we keep it 1.

For attention block, it will be focused on one class only. If you want multi attention then I suggest you look into this paper. (https://arxiv.org/pdf/1806.05372.pdf)
If you change it to softmax it will give an error i think becz the output to the next layer will be wrong.

from unet-segmentation-pytorch-nest-of-unets.

Y-P-W avatar Y-P-W commented on July 16, 2024

Thank you very much for your help recently. I will learn about multi attention and try to modify program. Looking forward to keeping in touch with you. My email : [email protected]

from unet-segmentation-pytorch-nest-of-unets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.