AttributeError: 'RecursiveScriptModule' object has no attribute 'copy'

See original GitHub issue

I want to ask a question about “AttributeError: ‘RecursiveScriptModule’ object has no attribute ‘copy’”

the following are my coding:

`(base) ubuntu@ubuntu:~/BM/BackgroundMattingV2$ python inference_video.py \

    --model-type mattingrefine \
    --model-backbone resnet50 \
    --model-backbone-scale 0.25 \
    --model-refine-mode sampling \
    --model-refine-sample-pixels 80000 \
    --model-checkpoint "/home/ubuntu/BM/content/torchscript_resnet50_fp32.pth" \
    --video-src "/content/src.mp4" \
    --video-bgr "/content/bgr.png" \
    --output-dir "/content/output/" \
    --output-type com fgr pha err ref

/home/ubuntu/anaconda3/envs/modnet_offline_3/lib/python3.6/site-packages/torch/serialization.py:589: UserWarning: ‘torch.load’ received a zip file that looks like a TorchScript archive dispatching to ‘torch.jit.load’ (call ‘torch.jit.load’ directly to silence this warning) " silence this warning)", UserWarning) Traceback (most recent call last): File “inference_video.py”, line 130, in <module> model.load_state_dict(torch.load(args.model_checkpoint, map_location=device), strict=False) File “/home/ubuntu/anaconda3/envs/modnet_offline_3/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 1196, in load_state_dict state_dict = state_dict.copy() File “/home/ubuntu/anaconda3/envs/modnet_offline_3/lib/python3.6/site-packages/torch/jit/_script.py”, line 561, in getattr return super(RecursiveScriptModule, self).getattr(attr) File “/home/ubuntu/anaconda3/envs/modnet_offline_3/lib/python3.6/site-packages/torch/jit/_script.py”, line 291, in getattr return super(ScriptModule, self).getattr(attr) File “/home/ubuntu/anaconda3/envs/modnet_offline_3/lib/python3.6/site-packages/torch/nn/modules/module.py”, line 948, in getattr type(self).name, name)) AttributeError: ‘RecursiveScriptModule’ object has no attribute ‘copy’ (base) ubuntu@ubuntu:~/BM/BackgroundMattingV2$ `

my environment is cuda11.1,pytorch 1.8.0, GEFORCE RTX 3090, and I suspect it’s a problem with the pytorch version? I

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
zhanghonglishanzaicommented, May 12, 2021

好的呢,哥哥

------------------ 原始邮件 ------------------ 发件人: "Peter @.>; 发送时间: 2021年5月12日(星期三) 下午4:26 收件人: @.>; 抄送: "Microsoft @.>; @.>; 主题: Re: [PeterL1n/BackgroundMattingV2] AttributeError: 'RecursiveScriptModule' object has no attribute 'copy' (#93)

亲,跟你讲了,你这行错了 –model-checkpoint “/home/ubuntu/BM/content/torchscript_resnet50_fp32.pth” \ 你不应该下载torchscript_resnet50_fp32.pth,要换成pytorch_resnet50.pth。

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

1reaction
PeterL1ncommented, May 12, 2021

亲,跟你讲了,你这行错了

--model-checkpoint "/home/ubuntu/BM/content/torchscript_resnet50_fp32.pth" \

你不应该下载torchscript_resnet50_fp32.pth,要换成pytorch_resnet50.pth

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pytorch: AttributeError: 'function' object has no attribute 'copy'
I am guessing this is what you did by mistake. You saved the function. torch.save(model.state_dict, 'model_state.pth').
Read more >
Error while loading state_dict - vision - PyTorch Forums
AttributeError : 'Net' object has no attribute 'copy'. Next I have used copy.copy(state_dict). Then I got a new error.
Read more >
AttributeError: 'RecursiveScriptModule' object has no attribute ...
在使用pytorch的pt文件推理时候,出现了报错,可以通过本文方法解决.
Read more >
torch.jit - Enchanter documentation
Arguments: m: A :class:`ScriptModule` to save. f: A file-like object (has to ... if r is None: raise AttributeError("'CompilationUnit' has no attribute ......
Read more >
torch.nn.modules.module — Catalyst 20.10.1 documentation
__dict__['_modules'] if name in modules: return modules[name] raise ModuleAttributeError("'{}' object has no attribute '{}'".format( type(self).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found