LeeJunHyun / Image_Segmentation

Pytorch implementation of U-Net, R2U-Net, Attention U-Net, and Attention R2U-Net.
2.66k stars 594 forks source link

RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 160 and 384 in dimension 2 at /pytorch/aten/src/TH/generic/THTensor.cpp:689 #80

Closed wlj567 closed 1 year ago

wlj567 commented 2 years ago

Traceback (most recent call last): File "/home/pxg/alex/U-Net/main.py", line 101, in main(config) File "/home/pxg/alex/U-Net/main.py", line 61, in main solver.train() File "/home/pxg/alex/U-Net/solver.py", line 140, in train for i, (images, GT) in enumerate(self.train_loader): File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 819, in next return self._process_data(data) File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data data.reraise() File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/_utils.py", line 369, in reraise raise self.exc_type(msg) RuntimeError: Caught RuntimeError in DataLoader worker process 0. Original Traceback (most recent call last): File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop data = fetcher.fetch(index) File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 47, in fetch return self.collate_fn(data) File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py", line 80, in default_collate return [default_collate(samples) for samples in transposed] File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py", line 80, in return [default_collate(samples) for samples in transposed] File "/home/pxg/DANet-master/venv/lib/python3.6/site-packages/torch/utils/data/_utils/collate.py", line 56, in default_collate return torch.stack(batch, 0, out=out) RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 160 and 384 in dimension 2 at /pytorch/aten/src/TH/generic/THTensor.cpp:689

Hello, can you help me see what the problem is? This is the result of batch_size = 8. When batch_size = 1, the computer gets stuck, can't move at all, and can only be restarted. Do you know what's going on? I hope you're free to help. Thank you.

wlj567 commented 2 years ago

I modified it according to the previous modification method, and a new error appears:TypeError: tensor is not a torch image.

I looked at some solutions, changing the location of normalize and ToTensor, but I didn't see ToTensor in the code

wlj567 commented 2 years ago

Transform.append(T.Resize((int(256aspect_ratio)-int(256aspect_ratio)%16,256))) Transform.append(T.Resize((224, 224))) Transform.append(T.ToTensor()) Transform = T.Compose(Transform)

I can make the program run, but the relevant evaluation index is not high. Thank you for sharing the code.

zhf600518 commented 2 years ago

wlj567 ,你好,可以把你运行成功的代码分享给我吗,万分感谢,邮箱1471268273@qq.com

wlj567 commented 2 years ago

wlj567 ,你好,可以把你运行成功的代码分享给我吗,万分感谢,邮箱1471268273@qq.com

抱歉我的电脑之前出问题了,文件没有保存。你可以跟着报错来,网上都有解决方法。

zhf600518 commented 2 years ago

好的,再麻烦问下,代码中只说用pytorch架构,未说基于python哪个版本。你还记得你的运行环境吗

------------------ 原始邮件 ------------------ 发件人: "LeeJunHyun/Image_Segmentation" @.>; 发送时间: 2022年3月22日(星期二) 下午3:07 @.>; @.**@.>; 主题: Re: [LeeJunHyun/Image_Segmentation] RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 160 and 384 in dimension 2 at /pytorch/aten/src/TH/generic/THTensor.cpp:689 (Issue #80)

wlj567 @.***

抱歉我的电脑之前出问题了,文件没有保存。你可以跟着报错来,网上都有解决方法。

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

wlj567 commented 2 years ago

python3.6,pytorch好像用的1.2

zhf600518 commented 2 years ago

非常感谢,能否加一下你得QQ或者微信。我得数据集划分一直跑不通,没有看懂代码。我微信zhf10776   qq 1471268273

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2022年3月25日(星期五) 上午9:13 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [LeeJunHyun/Image_Segmentation] RuntimeError: invalid argument 0: Sizes of tensors must match except in dimension 0. Got 160 and 384 in dimension 2 at /pytorch/aten/src/TH/generic/THTensor.cpp:689 (Issue #80)

python3.6,pytorch好像用的1.2

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

wlj567 commented 2 years ago

慢慢看吧,我也不怎么懂,只是调通了而已