libtorch配置vs2017


注意vs2013版本過低,建議用新版本vs

1、解壓libtorch

進入lib查看擁有的lib文件

 2、添加系統環境(一般是bin,但是libtorch的dll都在lib目錄里)

 3、VS新建項目,屬性管理器窗口新建自己的屬性表

 雙擊屬性表

 

 

 4、解決提醒std沖突問題,項目——屬性(注意不是雙擊屬性表,重新從項目——屬性進入,屬性表設置了不起作用)

屬性->C/C++ ->常規->SDL檢查->否

屬性->C/C++ ->語言->符號模式->否

至此,release模式完畢。

debug需要把lib目錄中的所有dll拷貝到工程目錄,或者https://www.cnblogs.com/chinahunter/p/11297778.html

 

以后新建項目,加載自己的屬性表,設置第4步即可。

【測試代碼】

#include<iostream>
#include<torch/script.h>
int main() {
    torch::Tensor t1 = torch::tensor({ 10,1,2 });
    std::cout << t1[0] << std::endl;
    system("pause");
}
//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");
}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM