DrSleep / light-weight-refinenet

Light-Weight RefineNet for Real-Time Semantic Segmentation
Other
739 stars 164 forks source link

I try to convert .pth.tar to onnx file, please help me!!! #49

Closed electronicYH closed 5 years ago

electronicYH commented 5 years ago

amax@amax:/data/yh/light-weight-refinenet$ python make_onnx.py Traceback (most recent call last): File "make_onnx.py", line 17, in torch.onnx.export(segmenter,dummy_input,"yh_refinenet.onnx",verbose=True) File "/home/amax/anaconda3/lib/python3.6/site-packages/torch/onnx/init.py", line 25, in export return utils.export(*args, **kwargs) File "/home/amax/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 131, in export strip_doc_string=strip_doc_string) File "/home/amax/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 363, in _export _retain_param_name, do_constant_folding) File "/home/amax/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 278, in _model_to_graph _disable_torch_constant_prop=_disable_torch_constant_prop) File "/home/amax/anaconda3/lib/python3.6/site-packages/torch/onnx/utils.py", line 183, in _optimize_graph torch._C._jit_pass_lower_all_tuples(graph) RuntimeError: tuple appears in op that does not forward tuples (VisitNode at /opt/conda/conda-bld/pytorch_1556653099582/work/torch/csrc/jit/passes/lower_tuples.cpp:117) frame #0: c10::Error::Error(c10::SourceLocation, std::string const&) + 0x45 (0x7fd313353dc5 in /home/amax/anaconda3/lib/python3.6/site-packages/torch/lib/libc10.so) frame #1: + 0xadf7d0 (0x7fd30e4777d0 in /home/amax/anaconda3/lib/python3.6/site-packages/torch/lib/libtorch.so.1) frame #2: + 0xadfa34 (0x7fd30e477a34 in /home/amax/anaconda3/lib/python3.6/site-packages/torch/lib/libtorch.so.1) frame #3: torch::jit::LowerAllTuples(std::shared_ptr&) + 0x13 (0x7fd30e477a73 in /home/amax/anaconda3/lib/python3.6/site-packages/torch/lib/libtorch.so.1) frame #4: + 0x3f59a4 (0x7fd3426259a4 in /home/amax/anaconda3/lib/python3.6/site-packages/torch/lib/libtorch_python.so) frame #5: + 0x12ce4a (0x7fd34235ce4a in /home/amax/anaconda3/lib/python3.6/site-packages/torch/lib/libtorch_python.so)

frame #36: __libc_start_main + 0xf0 (0x7fd349179830 in /lib/x86_64-linux-gnu/libc.so.6) my python: import torch from models.resnet import rf_lw50 from torch.autograd import Variable file = 'ckpt/checkpoint.pth.tar' segmenter = rf_lw50(15, False) segmenter = torch.nn.DataParallel(segmenter) ckpt = torch.load(file) segmenter.load_state_dict(ckpt['segmenter']) segmenter.cuda() segmenter.eval() dummy_input = Variable(torch.randn(1,3,360,640)).cuda() torch.onnx.export(segmenter,dummy_input,"yh_refinenet.onnx",verbose=True)
DrSleep commented 5 years ago

by default, the project code provided was not meant to be used with onnx. To make it usable, you should consult the onnx library wrt to this error

RuntimeError: tuple appears in op that does not forward tuples (VisitNode at /opt/conda/conda-bld/pytorch_1556653099582/work/torch/csrc/jit/passes/lower_tuples.cpp:117)