Hi,
I’m using PyTorch C++ in a high performance embedded system. I was able to create and train a custom model, and now I want to export it to ONNX to bring it into NVIDIA’s TensorRT. I found an example on how to export to ONNX if using the Python version of PyTorch, but I need to avoid Python if possible and only stick with PyTorch C++. Here’s the Python code snippet:

dummy_input = torch.randn(1, 3, 224, 224, device=‘cuda’)
input_names = [ “input” ]
output_names = [ “output” ]
torch.onnx.export(model, dummy_input, “my_model.onnx”, verbose=True, input_names=input_names, output_names=output_names)

How do I do this using the PyTorch C++ API?
If this ability does not work, is there a simple way to convert the output of:

torch::save(network, “network_and_weights.pt”);

to an ONNX file without needing to use the world of Python?
Thank you for any guidance.