libtorch在windows上的调用

转载:https://www.jianshu.com/p/542231f43207

libTorch下载

pytroch为windows端提供了2个版本的预编译好的libTorch动态链接库

  • Debug
  • Release


     
    image.png

测试环境

  • win10 64bit
  • vs2017
  • libTorch

配置过程

以Debug版本的libTorch为例

  • 添加include路径
  • 添加链接库lib路径
  • 添加lib名称
  • 添加环境变量
 
image.png
 
image.png
 
image.png

c10.lib
caffe2.lib
caffe2_detectron_ops.lib
caffe2_module_test_dynamic.lib
clog.lib
cpuinfo.lib
foxi_dummy.lib
foxi_loader.lib
libprotobuf-lited.lib
libprotobufd.lib
libprotocd.lib
onnx.lib
onnxifi_dummy.lib
onnxifi_loader.lib
onnx_proto.lib
torch.lib


测试代码

  • demo1
#include<iostream>
#include<torch/script.h>

int main() {

    torch::Tensor t1 = torch::tensor({ 10,1,2 });
    std::cout << t1[0] << std::endl;

    system("pause");

}
 
image.png
  • demo2
    2个Tensor计算矩阵乘法
#include<iostream>
#include<torch/script.h>

int main() {

    
    auto t1 = torch::tensor({ 1,2,3,4,5,6,7,8,9 }).reshape({ 3,3 });
    auto t2 = torch::tensor({ 1,0,2,6,1,1,5,3,2 }).reshape({ 3,3 });

    auto t3 = t1.mul(t2);

    std::cout << t3 << std::endl;
    

    system("pause");

}
 
image.png



作者:侠之大者_7d3f
链接:https://www.jianshu.com/p/542231f43207
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

原文地址:https://www.cnblogs.com/leoking01/p/13830890.html