plemeri / InSPyReNet

Official PyTorch implementation of Revisiting Image Pyramid Structure for High Resolution Salient Object Detection (ACCV 2022)
MIT License
321 stars 61 forks source link

unable to load jit model #37

Closed babyta closed 8 months ago

babyta commented 8 months ago

RuntimeError: The following operation failed in the TorchScript interpreter. Traceback of TorchScript, serialized code (most recent call last): File "code/torch/utils/misc.py", line 10, in forward x: Tensor) -> Tensor: model = self.model return (model).forward(x, )


  File "code/__torch__/lib/InSPyReNet.py", line 33, in forward
    _2 = ops.prim.NumToTensor(torch.size(x, 3))
    _3 = int(_2)
    _4, _5, _6, _7, _8, = (backbone).forward(x, )
                           ~~~~~~~~~~~~~~~~~ <--- HERE
    _9 = (context1).forward(_4, )
    _10 = (context2).forward(_5, )
  File "code/__torch__/lib/backbones/SwinTransformer.py", line 42, in forward
    input = torch.contiguous(_4)
    input0 = torch.transpose(torch.flatten(_4, 2), 1, 2)
    _13 = (_0).forward(H, W, (pos_drop).forward(input0, ), _8, _12, _7, _11, _6, _10, )
           ~~~~~~~~~~~ <--- HERE
    _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, = _13
    _26 = torch.view((norm0).forward(_14, ), [-1, _5, _9, 128])
  File "code/__torch__/lib/backbones/SwinTransformer.py", line 157, in forward
    _135 = torch.masked_fill(attn_mask, torch.ne(attn_mask, 0), -100.)
    mask = torch.masked_fill(_135, torch.eq(attn_mask, 0), 0.)
    _136 = (_0).forward(argument_3, H, W, argument_4, argument_5, )
            ~~~~~~~~~~~ <--- HERE
    _137 = (_1).forward(_136, H, W, argument_6, argument_7, mask, )
    _138 = (downsample).forward(_137, H, W, argument_8, argument_9, )
  File "code/__torch__/lib/backbones/SwinTransformer.py", line 235, in forward
    _173 = torch.permute(x4, [0, 1, 3, 2, 4, 5])
    x5 = torch.view(torch.contiguous(_173), [1, _158, _159, -1])
    x6 = torch.view(x5, [_147, int(torch.mul(H, W)), _149])
         ~~~~~~~~~~ <--- HERE
    _174 = (drop_path).forward()
    input = torch.add(argument_1, x6)

Traceback of TorchScript, original code (most recent call last):
F:\CODE\SODandDIS\InSPyReNet-main\lib\backbones\SwinTransformer.py(244): forward
D:\ProgramData\miniconda3\envs\py39pt1121\lib\site-packages\torch\nn\modules\module.py(1118): _slow_forward
D:\ProgramData\miniconda3\envs\py39pt1121\lib\site-packages\torch\nn\modules\module.py(1130): _call_impl
F:\CODE\SODandDIS\InSPyReNet-main\utils\misc.py(25): forward
D:\ProgramData\miniconda3\envs\py39pt1121\lib\site-packages\torch\nn\modules\module.py(1118): _slow_forward
D:\ProgramData\miniconda3\envs\py39pt1121\lib\site-packages\torch\nn\modules\module.py(1130): _call_impl
D:\ProgramData\miniconda3\envs\py39pt1121\lib\site-packages\torch\jit\_trace.py(967): trace_module
D:\ProgramData\miniconda3\envs\py39pt1121\lib\site-packages\torch\jit\_trace.py(750): trace
F:\CODE\SODandDIS\InSPyReNet-main\run\Inference.py(67): inference
F:\CODE\SODandDIS\InSPyReNet-main\run\Inference.py(177): <module>
RuntimeError: shape '[1, 51520, 128]' is invalid for input of size 7077888
babyta commented 8 months ago

my envs torch 1.12.1+cu113 python 3.9

babyta commented 8 months ago

Hello, maybe I don’t need trace, but this is still a problem, I will close it first.