DBNet.pytorch icon indicating copy to clipboard operation
DBNet.pytorch copied to clipboard

怎样导出pt模型

Open Ri-Yue-Shui-Hua opened this issue 4 years ago • 4 comments

大牛你好,我想知道怎么保存pt模型文件,我看到代码predict.py中有下面一段代码应该是保存pt模型文件用的,请问在哪里怎么调用呢? 原谅我一个刚入门的小白,提问这么初级的问题。

def save_depoly(model, input, save_path): traced_script_model = torch.jit.trace(model, input) traced_script_model.save(save_path)

Ri-Yue-Shui-Hua avatar Aug 20 '20 08:08 Ri-Yue-Shui-Hua

这个问题我已经解决了。但是有一个问题,模型固化为pt后,在c++下调用输入图片的尺寸只能归一化到固化模型时使用的尺寸,否则就会报错。猜测固化模型时只保留了固化模型时的参数,超出范围就会报错。好奇的是pytorch为什么可以这么灵活接受不同尺寸的输入,或者固化模型时还有更好的方法可以跟ytorch保持一致?

Ri-Yue-Shui-Hua avatar Sep 04 '20 03:09 Ri-Yue-Shui-Hua

能问一下你是如何解决的吗?我在转换的过程中总是报错: Traceback (most recent call last): File "tools/predict.py", line 146, in save_depoly(model, input, save_path) File "tools/predict.py", line 113, in save_depoly traced_script_model = torch.jit.trace(model, input) File "/home/dl/anaconda3/envs/yv5/lib/python3.7/site-packages/torch/jit/init.py", line 903, in trace name = _qualified_name(func) File "/home/dl/anaconda3/envs/yv5/lib/python3.7/site-packages/torch/_jit_internal.py", line 682, in _qualified_name name = obj.name AttributeError: 'Pytorch_model' object has no attribute 'name' 是否和torch版本有关?我是pip install torch==1.4来安装的pytorch

Crystalxd avatar Dec 09 '20 08:12 Crystalxd

看样子是你调用的位置或者传参不对。 下面这样可做参考  # 初始化网络     model = Pytorch_model(args.model_path, post_p_thre=args.thre, gpu_id=0)     input = torch.rand(1, 3, 736, 736).cuda() # wmz      save_depoly(model.model.eval(), input, "dbnet.pt")

------------------ 原始邮件 ------------------ 发件人: "WenmuZhou/DBNet.pytorch" <[email protected]>; 发送时间: 2020年12月9日(星期三) 下午4:45 收件人: "WenmuZhou/DBNet.pytorch"<[email protected]>; 抄送: "十二"<[email protected]>;"Author"<[email protected]>; 主题: Re: [WenmuZhou/DBNet.pytorch] 怎样导出pt模型 (#70)

能问一下你是如何解决的吗?我在转换的过程中总是报错: Traceback (most recent call last): File "tools/predict.py", line 146, in save_depoly(model, input, save_path) File "tools/predict.py", line 113, in save_depoly traced_script_model = torch.jit.trace(model, input) File "/home/dl/anaconda3/envs/yv5/lib/python3.7/site-packages/torch/jit/init.py", line 903, in trace name = _qualified_name(func) File "/home/dl/anaconda3/envs/yv5/lib/python3.7/site-packages/torch/_jit_internal.py", line 682, in _qualified_name name = obj.name AttributeError: 'Pytorch_model' object has no attribute 'name' 是否和torch版本有关?我是pip install torch==1.4来安装的pytorch

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

Ri-Yue-Shui-Hua avatar Dec 10 '20 14:12 Ri-Yue-Shui-Hua

非常感谢!

Crystalxd avatar Dec 11 '20 01:12 Crystalxd