I got the Namespace “torch::jit” has no member “trace” error while saving a custom trained model. Environments -
- libtorch-win-shared-with-deps-2.6.0+cu124
- Visual Studio 2022 - Version- 17.10.2
code snippet
try {
auto example_input = torch::rand({ 1, 3, img_height, img_width }).to(device);
// Trace the model.
auto traced_module = torch::jit::trace(*model, example_input);
// Save the traced TorchScript module.
traced_module.save(tensor_script_save_path);
std::cout << "Converted best model to " << tensor_script_save_path << " successfully." << std::endl;
}
catch (const c10::Error& error) {
std::cerr << "Error during TorchScript export: " << error.what() << std::endl;
return -1;
}
Any suggestions?
Thanks.