3

I am using YOLACT++ and I want to deploy it using C++. Originally the model is saved as yolact.pth file and I realized from the issues that I couldn't directly convert .pth to .pt file that can be called in C++ see this issue and I would need to do convert it first to ONNX which gives out yolact.onnx as the output. I converted it to ONNX using this solution in the issues and in the comments below this one you can see the terminal commands he uses to achieve the yolact.onnx converted model from yolact.pth.

So my issue is I don't really understand what to do next to deploy it using C++. Should I be looking for solutions to convert from yolact.onnx to yolact.pt or can yolact.onnx be called from C++? There's an interesting direction given in one of the issues here for this work flow: Pytorch->ONNX->NCNN which he tested with C++ inference on ARM device. Is this what I am looking for. I am not very familiar with C++ so I dont know the direction.

I also tried adding this to end of of eval.py where model is being called:

    sm = torch.jit.script(net)
    sm.save("Yolact.pt")
    

and I got error:

    torch.jit.frontend.UnsupportedNodeError: with statements aren't 
    supported: (line 570 in yolact.py)

and line 570 is:

     with timer.env('backbone'):

I commented it out and it gave error on the next "timer.env" in line 574 and so on!

Areeb Muzaffar
  • 197
  • 2
  • 15
  • 1
    Did you try jit tracing it first and see if that works for you? – Hossein Oct 27 '20 at 09:26
  • @Rika hi im not sure. Can you check my question again I edited it and I put in the thing I added in my code using pytorch tutorials on website – Areeb Muzaffar Oct 27 '20 at 12:18
  • @Rika I tried tracing again using example = torch.rand(1, 3, 550, 550), traced_script_module = torch.jit.trace(net, example) traced_script_module.save("Yolact.pt") at the end of eval.py but it gives me errors like RuntimeError: Tracer cannot infer type of [{'detection': {'box': tensor([[-0.4274, -0.5033, 0.4412, 0.4673], and it goes on and on – Areeb Muzaffar Oct 27 '20 at 13:04
  • and also I dont know what values to put in example=torch.rand(x,x,x,x) my trained images are of size 550x550 – Areeb Muzaffar Oct 27 '20 at 13:13
  • youre doing it correctly but It seems your model doesn't support jit tracing,as indicated in the link you posted. unfortunetaly I'm not familair with your model/onnx. – Hossein Oct 27 '20 at 13:46
  • Were you actually able to convert one of the Yolact++ models to ONNX? Such as yolact_plus_base_54_800000.pth to yolact_plus_base_54_800000.onnx. If when I try with Ma-Dan's solution (as you link above), I get: 'yolact_plus_base_config' is not defined. My command line is: python3 eval.py --trained_model=yolact_plus_base_54_800000.pth --score_threshold=0.3 --top_k=100 --cuda=False --image=image.jpg – Bryan Greenway Jan 27 '21 at 21:53
  • Did you solve your question? – Curious G. Jan 21 '22 at 17:04

0 Answers0