RethinkVSRAlignment icon indicating copy to clipboard operation
RethinkVSRAlignment copied to clipboard

A question about the PSRT-Sliding model in psrt_sliding_arch.py

Open laulampaul opened this issue 2 years ago • 7 comments

When I run the code [psrt_sliding_arch.py] , I face one bug

Traceback (most recent call last): File "model.py", line 969, in x = model(x) File "/home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "model.py", line 859, in forward feats = self.forward_features(x) File "model.py", line 833, in forward_features x = layer(x.contiguous(), x_size , attn_mask) File "/home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "model.py", line 502, in forward x = self.residual_group(x, x_size,attn_mask) File "/home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "model.py", line 401, in forward x = blk(x, x_size,attn_mask) File "/home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "model.py", line 287, in forward attn_windows = attn_windows.view(-1, *(self.window_size + [c,])) TypeError: can only concatenate tuple (not "list") to tuple

And I try to change attn_windows = attn_windows.view(-1, *(self.window_size + [c,])) to attn_windows = attn_windows.view(-1, self.window_size[0], self.window_size[1],self.window_size[2],c)

And face a new bug

(PyTorch-1.8) [ma-user rethinking]$python model.py /home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/requests/init.py:104: RequestsDependencyWarning: urllib3 (1.26.12) or chardet (5.0.0)/charset_normalizer (2.0.12) doesn't match a supported version! RequestsDependencyWarning) /home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/torch/functional.py:478: 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:2895.) return _VF.meshgrid(tensors, **kwargs) # type: ignore[attr-defined] Traceback (most recent call last): File "model.py", line 969, in x = model(x) File "/home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(*input, **kwargs) File "model.py", line 859, in forward feats = self.forward_features(x) File "model.py", line 833, in forward_features x = layer(x.contiguous(), x_size , attn_mask) File "/home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(input, **kwargs) File "model.py", line 502, in forward x = self.residual_group(x, x_size,attn_mask) File "/home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(input, **kwargs) File "model.py", line 401, in forward x = blk(x, x_size,attn_mask) File "/home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in _call_impl return forward_call(input, **kwargs) File "model.py", line 281, in forward attn_windows = self.attn(x_windows, mask=attn_mask) # BnW, WdWhWw, C File "/home/ma-user/anaconda3/envs/PyTorch-1.8/lib/python3.7/site-packages/torch/nn/modules/module.py", line 1130, in call_impl return forward_call(*input, **kwargs) File "model.py", line 162, in forward attn = attn.view(B // nW, nW, self.num_heads, N, N) + mask.unsqueeze(1).unsqueeze(0) RuntimeError: shape '[1, 2178, 6, 128, 128]' is invalid for input of size 321159168

How can I solve it ??

laulampaul avatar Oct 10 '22 07:10 laulampaul

Can you provide more information of your running conditions?

Shuweis avatar Oct 31 '22 15:10 Shuweis

python== 3.8.8 pytorch==1.9.0 torchvision==0.9.0

laulampaul avatar Nov 01 '22 12:11 laulampaul

I mean how do you run the psrt_sliding_arch.py? Your input size or other information

Shuweis avatar Nov 02 '22 04:11 Shuweis

just use the code in psrt_sliding_arch.py

if name == 'main': upscale = 4 window_size = (2, 8, 8) height = (1024 // upscale // window_size[1] + 1) * window_size[1] width = (1024 // upscale // window_size[2] + 1) * window_size[2]

model = SwinIRFM(
    img_size=height,
    patch_size=1,
    in_chans=3,
    embed_dim=96,
    depths=(6, 6, 6, 6),
    num_heads=(6, 6, 6, 6),
    window_size=window_size,
    mlp_ratio=2,
    qkv_bias=True,
    qk_scale=None,
    drop_rate=0.,
    attn_drop_rate=0.,
    drop_path_rate=0.1,
    norm_layer=nn.LayerNorm,
    ape=False,
    patch_norm=True,
    use_checkpoint=False,
    upscale=2,
    img_range=1.,
    upsampler='pixelshuffle',
)

print(model)
#print(height, width, model.flops() / 1e9)

x = torch.randn((1, 5, 3, height, width))
x = model(x)
print(x.shape)

laulampaul avatar Nov 02 '22 08:11 laulampaul

I also show this problem: TypeError: can only concatenate tuple (not "int") to tuple. How can I solve it?

chenzean avatar Jul 01 '23 00:07 chenzean

Meet the same problem. How to solve it?

DachunKai avatar Jun 17 '24 08:06 DachunKai

I also meet the question, what can I do??

Desertstudentltsx avatar Jun 18 '24 15:06 Desertstudentltsx