HuCaoFighting / Swin-Unet

[ECCVW 2022] The codes for the work "Swin-Unet: Unet-like Pure Transformer for Medical Image Segmentation"
1.78k stars 323 forks source link

Window_partition Runtime Error #112

Open sibi-venti opened 6 months ago

sibi-venti commented 6 months ago

my input image 750x750 -> grayscale image 0 to 255 window size 10 error

SwinTransformerSys expand initial----depths:[2, 2, 2, 2];depths_decoder:[1, 2, 2, 2];drop_path_rate:0.2;num_classes:20
/home/sibi/.local/lib/python3.10/site-packages/torch/functional.py:512: UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. (Triggered internally at ../aten/src/ATen/native/TensorShape.cpp:3587.)
  return _VF.meshgrid(tensors, **kwargs)  # type: ignore[attr-defined]
window_ torch.Size([1, 187, 187, 1])
Traceback (most recent call last):
  File "/home/sibi/dev/Swin-Unet/train.py", line 95, in <module>
    net = ViT_seg(config, img_size=args.img_size, num_classes=args.num_classes).cuda()
  File "/home/sibi/dev/Swin-Unet/networks/vision_transformer.py", line 30, in __init__
    self.swin_unet = SwinTransformerSys(img_size=config.DATA.IMG_SIZE,
  File "/home/sibi/dev/Swin-Unet/networks/swin_transformer_unet_skip_expand_decoder_sys.py", line 627, in __init__
    layer = BasicLayer(dim=int(embed_dim * 2 ** i_layer),
  File "/home/sibi/dev/Swin-Unet/networks/swin_transformer_unet_skip_expand_decoder_sys.py", line 415, in __init__
    self.blocks = nn.ModuleList([
  File "/home/sibi/dev/Swin-Unet/networks/swin_transformer_unet_skip_expand_decoder_sys.py", line 416, in <listcomp>
    SwinTransformerBlock(dim=dim, input_resolution=input_resolution,
  File "/home/sibi/dev/Swin-Unet/networks/swin_transformer_unet_skip_expand_decoder_sys.py", line 219, in __init__
    mask_windows = window_partition(img_mask, self.window_size)  # nW, window_size, window_size, 1
  File "/home/sibi/dev/Swin-Unet/networks/swin_transformer_unet_skip_expand_decoder_sys.py", line 38, in window_partition
    x = x.view(B, H // window_size, window_size, W // window_size, window_size, C)
RuntimeError: shape '[1, 18, 10, 18, 10, 1]' is invalid for input of size 34969

what is the relation between the image size and window size?