I installed libtorch1.5 and try to use it train model, I want use C++ API to trace the trained model and save it. But I just find the API torch::jit::tracer::trace, how to use it? I can’t get any explain about these API, who can give me some advice?
# An instance of your model. model = torch.load('my_model.pth') model.eval() # An example input you would normally provide to your model's forward() method. example = torch.rand(1, 3, 224, 224) # Use torch.jit.trace to generate a torch.jit.ScriptModule via tracing. traced_script_module = torch.jit.trace(model.cuda(), example.cuda()) # save it traced_script_module.save("model_cpp.pt")
First of all, thank you for your answer, I actually ues libtorch(c++ API), so I want to train and save finally model in the same platform, but I can’t find any instructions about how to trace or scrpt model in C++ platform. You may not get my problems.