Unable to load a model. Model is there, still cannot load the model. Below is my code. Any help appreciated.
Libtorch 2.6 +cu124
Visual Studio 2022
int LoadModel(const std::filesystem::path& modelPath) {
try {
std::cout << " Loading model from path: " << modelPath << std::endl;
if (!std::filesystem::exists(modelPath)) {
std::cerr << "Error: Model file not found at " << modelPath << std::endl;
return -1;
}
if (modelPath.empty()) {
std::cerr << "Error: Model path is empty!" << std::endl;
return -1;
}
if (!std::filesystem::exists(modelPath)) {
std::cerr << "Error: Model file does not exist at: " << modelPath << std::endl;
return -1;
}
std::cout << "absolute model path: " << std::filesystem::absolute(modelPath) << std::endl;
// Try loading the model
network = torch::jit::load(modelPath.string());
network.eval(); // Set to evaluation mode
std::cout << "Model loaded successfully!" << std::endl;
return 0;
}
catch (const c10::Error& e) {
std::cerr << " Error loading model: " << e.what() << std::endl;
std::cerr << "File path: " << modelPath << std::endl;
return -1;
}
}
int main() {
std::filesystem::path modelPath = "nws_736_1280_b1.torchscript"; // Path to your model file
int status = LoadModel(modelPath);
if (status == 0) {
std::cout << "Model is ready for inference!" << std::endl;
}
else {
std::cerr << "Failed to load model!" << std::endl;
}
return 0;
}