open-mmlab / mmocr

OpenMMLab Text Detection, Recognition and Understanding Toolbox
https://mmocr.readthedocs.io/en/dev-1.x/
Apache License 2.0
4.27k stars 743 forks source link

How to convert torch model to torch jit model ? #249

Open VpkPrasanna opened 3 years ago

VpkPrasanna commented 3 years ago

How to convert psenet_r50_fpnf_600e_icdar2015_pretrain-eefd8fe6.pth model to torch jit model , when i tried so i am getting an error of The code which i used to convert is def convert_model(model,image): model = torch.load(model) with torch.jit.optimized_execution(True,): traced_model = torch.jit.trace(model,image) return traced_model Error which i got Traceback (most recent call last): File "/home/laptop-obs-128/Downloads/funhouse-backend/app/server/ai_runner/ocr/models/model_conversion.py", line 13, in <module> det_traced_model = convert_model(model=det_model,image=test_image) File "/home/laptop-obs-128/Downloads/funhouse-backend/app/server/ai_runner/ocr/models/model_conversion.py", line 10, in convert_model traced_model = torch.jit.trace(model,image) File "/home/laptop-obs-128/miniconda3/envs/funhouse-backend/lib/python3.9/site-packages/torch/jit/_trace.py", line 777, in trace name = _qualified_name(func) File "/home/laptop-obs-128/miniconda3/envs/funhouse-backend/lib/python3.9/site-packages/torch/_jit_internal.py", line 876, in _qualified_name raise RuntimeError("Could not get name of python class object") RuntimeError: Could not get name of python class object

cuhk-hbsun commented 3 years ago

We are locating the bug. It may be because the data type of image you give to model since model forward need both image and image_metas.