PaddleOCR2Pytorch icon indicating copy to clipboard operation
PaddleOCR2Pytorch copied to clipboard

请问作者已经转化好的ptocr模型是基于pytorch哪个版本的呢?另:我保存成pt文件时会出错是什么原因您知道吗?

Open PaulX1029 opened this issue 2 years ago • 13 comments

我想转化成Android可以使用的pt或ptl文件,使用官方提供的转化手段如下: 在predict_det.pt加载好检测的v3模型后添加代码如下: example = torch.rand(1, 3, 640, 640) traced_script_module = torch.jit.trace(self.net, example) traced_script_module_optimized = optimize_for_mobile(traced_script_module) traced_script_module_optimized._save_for_lite_interpreter("ptocr_v3_det.ptl") 出现如下错误: image Encountering a dict at the output of the tracer might cause the trace to be incorrect, this is only valid if the container structure does not change based on the module's inputs. Consider using a constant container instead (e.g. for list, use a tuple instead. for dict, use a NamedTuple instead). If you absolutely need this and know the side effects, pass strict=False to trace() to allow this behavior. 请问您有什么思路或者解决办法吗?或者后续会提供保存好的pt模型吗? 非常感谢!!!

PaulX1029 avatar May 17 '22 01:05 PaulX1029

在我本地环境保存几个rec模型为ptl文件时,总是出现如下类似的错误,对应的网络层缺少一些模块,请问作者可知道是什么原因吗? image

PaulX1029 avatar May 17 '22 06:05 PaulX1029

torch.jit.trace时需要修改DB网络输出,list改为tuple,dict改为NamedTuple。不然torch.jit.trace不支持

frotms avatar May 17 '22 06:05 frotms

rec的命令是?

frotms avatar May 17 '22 06:05 frotms

rec的命令是?

from torch.utils.mobile_optimizer import optimize_for_mobile example = torch.rand(1, 3, 640, 640) mobile = torch.jit.trace(self.net, example) traced_script_module_optimized = optimize_for_mobile(mobile) traced_script_module_optimized._save_for_lite_interpreter("ptocr_rec_v2.ptl") rec的命令也是如此

PaulX1029 avatar May 17 '22 06:05 PaulX1029

torch.jit.trace时需要修改DB网络输出,list改为tuple,dict改为NamedTuple。不然torch.jit.trace不支持

请问具体是在哪里?base_model.py主网络构建里没有找到

PaulX1029 avatar May 17 '22 06:05 PaulX1029

rec的命令是?

from torch.utils.mobile_optimizer import optimize_for_mobile example = torch.rand(1, 3, 640, 640) mobile = torch.jit.trace(self.net, example) traced_script_module_optimized = optimize_for_mobile(mobile) traced_script_module_optimized._save_for_lite_interpreter("ptocr_rec_v2.ptl") rec的命令也是如此

做rec保存模型时 assert H == 1这句话会报错 image

PaulX1029 avatar May 17 '22 06:05 PaulX1029

torch.jit.trace时需要修改DB网络输出,list改为tuple,dict改为NamedTuple。不然torch.jit.trace不支持

请问具体是在哪里?base_model.py主网络构建里没有找到

db的head里

frotms avatar May 18 '22 04:05 frotms

rec的命令是?

from torch.utils.mobile_optimizer import optimize_for_mobile example = torch.rand(1, 3, 640, 640) mobile = torch.jit.trace(self.net, example) traced_script_module_optimized = optimize_for_mobile(mobile) traced_script_module_optimized._save_for_lite_interpreter("ptocr_rec_v2.ptl") rec的命令也是如此

做rec保存模型时 assert H == 1这句话会报错 image

把assert删掉

frotms avatar May 18 '22 04:05 frotms

torch.jit.trace时需要修改DB网络输出,list改为tuple,dict改为NamedTuple。不然torch.jit.trace不支持

请问具体是在哪里?base_model.py主网络构建里没有找到

db的head里

还是想冒昧问您一下,是这个地方吗?我应该改为NamedTuple吗? image 修改为tuple或NamedTuple后还是会出现trace不支持的情况: RuntimeError: Encountering a dict at the output of the tracer might cause the trace to be incorrect, this is only valid if the container structure does not change based on the module's inputs. Consider using a constant container instead (e.g. for list, use a tuple instead. for dict, use a NamedTuple instead). If you absolutely need this and know the side effects, pass strict=False to trace() to allow this behavior.

PaulX1029 avatar May 26 '22 09:05 PaulX1029

image 我使用这种方式成功了,但是出现了这样的提示,请问有没有影响呢? TracerWarning: Iterating over a tensor might cause the trace to be incorrect. Passing a tensor of different shape won't change the number of iterations executed (and might lead to errors or silently give incorrect results).

PaulX1029 avatar May 26 '22 09:05 PaulX1029

请问可以分享一下怎么转换.pt文件吗

juneane avatar Mar 31 '23 14:03 juneane

请问可以分享一下怎么转换.pt文件吗

模型输出部分用tuple替换字典就好了

PaulX1029 avatar Mar 31 '23 14:03 PaulX1029

我转化PT文件后在移动端使用效果很差,不知道楼主有没有遇到

renmoqiqi avatar Nov 21 '23 09:11 renmoqiqi