libtorch的vs2017 64位 release 的C++开发包,平台集v141。include配置【libtorch\include ;libtorch\include\torch\csrc\api\include】;lib配置【libtorch\lib ; caffe2_detectron_ops.lib、caffe2_module_test_dynamic.lib、torch.lib、torch_cpu.lib、c10.lib、fbgemm.lib、cpuinfo.lib、clog.lib、libprotoc.lib、libprotobuf.lib、mkldnn.lib、libprotobuf-lite.lib、asmjit.lib】;属性->C/C++ ->常规->SDL检查->否;属性->C/C++ ->语言->符号(合)模式->否;
测试例程:
#include
#include
struct Net : torch::nn::Module {
Net(int64_t N, int64_t M) {
W = register_parameter("W", torch::randn({ N, M }));
b = register_parameter("b", torch::randn(M));
}
torch::Tensor forward(torch::Tensor input) {
return torch::addmm(b, input, W);
}
torch::Tensor W, b;
};
int main()
{
std::cout << "Hello World!\n";
torch::Tensor tensor = torch::eye(3);// torch::eye(3);
std::cout << tensor << std::endl;
Net net(4, 5);
for (const auto& p : net.parameters()) {
std::cout << p << std::endl;
}
system("PAUSE");
}
1