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名称
- 添加环境变量
![](http://upload-images.jianshu.io/upload_images/11478104-78364e27d032187c.png?imageMogr2/auto-orient/strip|imageView2/2/w/696/format/webp)
image.png
![](http://upload-images.jianshu.io/upload_images/11478104-0251d64390290669.png?imageMogr2/auto-orient/strip|imageView2/2/w/1200/format/webp)
image.png
![](http://upload-images.jianshu.io/upload_images/11478104-5be2fe4a01162c3b.png?imageMogr2/auto-orient/strip|imageView2/2/w/1091/format/webp)
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");
}
![](http://upload-images.jianshu.io/upload_images/11478104-9ca69f51babb329d.png?imageMogr2/auto-orient/strip|imageView2/2/w/370/format/webp)
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");
}
![](http://upload-images.jianshu.io/upload_images/11478104-d242a3513b98307a.png?imageMogr2/auto-orient/strip|imageView2/2/w/356/format/webp)
image.png
作者:侠之大者_7d3f
链接:https://www.jianshu.com/p/542231f43207
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
_________________________________________________________________________________________________________________________________________________
每一个不曾起舞的日子,都是对生命的辜负。
But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采
每一个不曾起舞的日子,都是对生命的辜负。
But it is the same with man as with the tree. The more he seeks to rise into the height and light, the more vigorously do his roots struggle earthward, downward, into the dark, the deep - into evil.
其实人跟树是一样的,越是向往高处的阳光,它的根就越要伸向黑暗的地底。----尼采