If it is possible to use swig to call c++ inferface by python

pytorch:1.3
libtorch:1.3
cuda:10.1
ubuntu:18.04
python:3.6

i want to code a common predict server, separate the whole flow into three parts:preprocess, predict and postprocess, among them, preprocess and postprocess are coded by python, preidct is coded by c++, the definition in c++ is :
at::Tensor do_predict(std::vector<torch::jit::IValue> inputs)
c++ module is wrapped by swig, and called in python:

with open(r"cat.jpg", 'rb') as f:
    image_bytes = f.read()
tensor = []
t = preprocess.transform_image(image_bytes)
tensor.append(t)
res = predict.do_predict(tensor)

as you can see, it got the error:

Traceback (most recent call last):
  File "app.py", line 24, in <module>
    res = predict.do_predict(tensor)
TypeError: in method 'do_predict', argument 1 of type 'std::vector< torch::jit::IValue >'

i really confused whether the whole solutions(python->c+±>python) is ok, if it is ok, how to transform list<torch.tensor>
to std::vector< torch::jit::IValue >, and at::Tensor to torch.tensor. if you know, please tell me, i will really appreciate

1 Like

Was there ever a solution to this?