美文网首页
PyTorch分类模型移植到Windows环境下并用C++调用

PyTorch分类模型移植到Windows环境下并用C++调用

作者: 几时见得清梦 | 来源:发表于2019-08-20 18:33 被阅读0次

错误及解决

    • 错误:CUDA support not available with 32-bit windows. Did you forget to set Win64 in the generator target?
    • 解决: try to add -DCMAKE_GENERATOR_PLATFORM=x64 to your cmake command
    • 错误:vs中找不到torch/torch.h
    • 解决:libtorch的头文件路径为:D:\ainnovation\projects\ciwa\pth_to_cpp\lib\torch\libtorch-win-shared-with-deps-debug-latest\libtorch\include\torch\csrc\api\include
    • 错误:在build文件夹下,cmake时报错:CMake Error: Could not create named generator Visual Studio 15
    • 解决:1. 因为装的有cygwin,cygwin里面包含了cmake,所以在环境变量path里面有cygwin的目录。windows平台的cmake的路径在cygwin的后面。因此将cmake的目录路径移到cygwin前面就解决了。2. 见参考文献3

成功的cmake命令(vs2017):cmake -DCMAKE_PREFIX_PATH=libtorch-win-shared-with-deps-debug-latest\libtorch -DCMAKE_BUILD_TYPE=Release -G "Visual Studio 15 Win64" ..

    • 错误:PyTorch1.2中某些API更新导致报错
    • 解决:
change:
std::shared_ptr<torch::jit::script::Module> module = torch::jit::load(s_model_name);
to:
torch::jit::script::Module module = torch::jit::load(s_model_name, torch::kCUDA);

change:
torch::Tensor out_tensor = module->forward({input_tensor}).toTensor();
to:
torch::Tensor out_tensor = module.forward({input_tensor}).toTensor();

参考

  1. PyTorch官方文档
  2. CSDN:Win10+VS2017+PyTorch(libtorch) C++ 基本应用
  3. 关于Cmake Error:Could not create named generator Visual Studio 14 2015 win64的解决方法
  4. 简书:pytroch学习(二十一)—C++(libTorch)调用pytroch预训练模型
  5. PyTorch官方论坛:Broken API in libtorch 1.2
  6. PyTorch官方文档

相关文章

网友评论

      本文标题:PyTorch分类模型移植到Windows环境下并用C++调用

      本文链接:https://www.haomeiwen.com/subject/khfmsctx.html