使用的是libtorch cpu 1.4.0 debug版本
网络模型是https://link.zhihu.com/?target=https%3A//github.com/NathanUA/BASNet
以下是代码:
#include <torch/torch.h>
#include <torch/script.h>
#include <iostream>
#include <memory>
int main(int argc, const char* argv[]) {
if (argc != 2) {
std::cerr << "usage: example-app <path-to-exported-script-module>\n";
return -1;
}
torch::jit::script::Module module;
try {
// Deserialize the ScriptModule from a file using torch::jit::load().
//module = torch::jit::load("C:\\Users\\Kiven\\Desktop\\BASNet-master\\basnet.pt");//
module = torch::jit::load(argv[1]);
}
catch (const c10::Error& e) {
std::cerr << "error loading the model\n";
return -1;
}
std::cout << "ok\n";
// Create a vector of inputs.
std::vector<torch::jit::IValue> inputs;
inputs.push_back(torch::ones({ 1, 3, 64, 64 }));
// Execute the model and turn its output into a tensor.
at::Tensor output = module.forward(inputs).toTensor();
std::cout << output.slice(/*dim=*/1, /*start=*/0, /*end=*/10) << '\n';
}
//
控制台命令出错提示⬆
debug下运行异常显示:
0x00007FF9C1943B29 处(位于 example-app.exe 中)引发的异常: Microsoft C++ 异常: c10::Error,位于内存位置 0x00000040C4EFF1C0 处。
0x00007FF9C1943B29 处(位于 example-app.exe 中)有未经处理的异常: Microsoft C++ 异常: c10::Error,位于内存位置 0x00000040C4EFF1C0 处。
还有一个问题:输出 ok代表我的.pt文件是正常可以用的嘛?
点击下重试,看堆栈在哪里
能够正常输出了