第一次用libtorch,本人用网上的libtorch测试代码(如下)
#include <torch/script.h> // One-stop header.
#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;
}
// Deserialize the ScriptModule from a file using torch::jit::load().
torch::jit::script::Module module = torch::jit::load(argv[1]);
assert(module != nullptr);
std::cout << "ok\n";
}
<torch / script.h>头文件包含运行该示例所需的LibTorch库中的所有相关包含。我们的应用程序接受序列化PyTorch ScriptModule的文件路径作为其唯一的命令行参数,然后使用torch :: jit :: load()函数继续反序列化模块,该函数将此文件路径作为输入。作为回报,我们收到一个指向torch :: jit :: script :: Module的共享指针,相当于C ++中的torch.jit.ScriptModule。目前,我们只验证此指针不为null。我们将研究如何在接下来执行它。
以上是上述代码的描述。
运行的时候发现“assert(module != nullptr);”语句发生错误:
请问有人知道这是为什么吗?