amp=args.amp) File "D:/segmentation/Pytorch-UNet-master/train.py", line 88, in train_net masks_pred = net(images) File "D:\ProgramData\Anacond_runtimeer">
当前位置:   article > 正文

Sizes of tensors must match except in dimension 1. Expected size 24 but got size 25 for tensor numbe_runtimeerror: sizes of tensors must match except i

runtimeerror: sizes of tensors must match except in dimension 1. expected si

在做图像分割的时候遇到了错误,错误如下:

File "D:/segmentation/Pytorch-UNet-master/train.py", line 193, in <module>
    amp=args.amp)
  File "D:/segmentation/Pytorch-UNet-master/train.py", line 88, in train_net
    masks_pred = net(images)
  File "D:\ProgramData\Anaconda3\envs\mytorch\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\ProgramData\Anaconda3\envs\mytorch\lib\site-packages\segmentation_models_pytorch\base\model.py", line 16, in forward
    decoder_output = self.decoder(*features)
  File "D:\ProgramData\Anaconda3\envs\mytorch\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\ProgramData\Anaconda3\envs\mytorch\lib\site-packages\segmentation_models_pytorch\unet\decoder.py", line 121, in forward
    x = decoder_block(x, skip)
  File "D:\ProgramData\Anaconda3\envs\mytorch\lib\site-packages\torch\nn\modules\module.py", line 1110, in _call_impl
    return forward_call(*input, **kwargs)
  File "D:\ProgramData\Anaconda3\envs\mytorch\lib\site-packages\segmentation_models_pytorch\unet\decoder.py", line 39, in forward
    x = torch.cat([x, skip], dim=1)
RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 24 but got size 25 for tensor number 1 in the list.
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

从错误的分析得知是维度没有对上。将x和skip的维度打印出来:

torch.Size([2, 448, 24, 18]) torch.Size([2, 160, 25, 18])
  • 1

这就对应上上面的错误了。
出现这个错误的原因是在输入图片的时候,没有将图像resize成512×512大小,导致维度不一致!
将图片resize后就可以解决。
在打印x和skip的维度:

torch.Size([2, 448, 32, 32]) torch.Size([2, 160, 32, 32])
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Cpp五条/article/detail/149609
推荐阅读
相关标签
  

闽ICP备14008679号