【发布时间】:2020-03-19 06:04:29
【问题描述】:
按照官方 PyTorch tutorial,我在 Python 中创建了模型,通过跟踪将其转换为 Torch 脚本,并将脚本模块保存到 .pt 文件中。加载模型和 CMakeLists 的 C++ 代码与教程中的相同。
我下载了LibTorch 1.3 (stable, Windows, no CUDA, release)并解压,所以我的目录结构是:
│ ├────神器 │ traced_resnet_model.pt │ ├───cmakeapp │ │ CMakeLists.txt │ │ example-app.cpp │ │ ├────libtorch │ │ 构建哈希 │ ├───bin │ ├───cmake │ ├───包括 │ ├───lib │ ├───分享 │ └───测试我将 Visual Studio 2019 与 CMake 作为组件安装,因此我运行 VS2019 的开发人员命令提示符和 cd 到项目目录 (cmakeapp)。
根据指南,我运行了以下命令来构建应用程序:
mkdir build
cd build
cmake -DCMAKE_PREFIX_PATH=..\libtorch ..
make
CMake 似乎成功了,除了一些警告:
CMake Warning (dev) at D:/dox/projects/AI/torchscript/libtorch/share/cmake/Caffe
2/public/utils.cmake:57 (if):
Policy CMP0054 is not set: Only interpret if() arguments as variables or
keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
Quoted variables like "MSVC" will no longer be dereferenced when the policy
is set to NEW. Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
D:/dox/projects/AI/torchscript/libtorch/share/cmake/Caffe2/Caffe2Config.cmake:
121 (caffe2_interface_library)
D:/dox/projects/AI/torchscript/libtorch/share/cmake/Torch/TorchConfig.cmake:40
(find_package)
CMakeLists.txt:4 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
CMake Warning (dev) at D:/dox/projects/AI/torchscript/libtorch/share/cmake/Torch
/TorchConfig.cmake:90 (if):
Policy CMP0054 is not set: Only interpret if() arguments as variables or
keywords when unquoted. Run "cmake --help-policy CMP0054" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
Quoted variables like "MSVC" will no longer be dereferenced when the policy
is set to NEW. Since the policy is not set the OLD behavior will be used.
Call Stack (most recent call first):
CMakeLists.txt:4 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
现在是第一期,make 和 nmake 都不起作用:
'make' is not recognized as an internal or external command, operable program or batch file.
D:\dox\projects\AI\torchscript\cmakeapp\build>nmake
Microsoft (R) Program Maintenance Utility Version 14.23.28107.0 Copyright (C) Microsoft Corporation. All rights reserved.
NMAKE : fatal error U1064: MAKEFILE not found and no target specified Stop.
我错过了什么吗?
第二,我找到了生成的custom_ops.sln文件,于是在Visual Studio中打开。该项目提供 4 种不同的配置:Debug、MinSizeRel、Release 和 RelWithDebInfo。构建除 Release 之外的任何东西都会失败:
LINK : fatal error LNK1181: cannot open input file 'torch-NOTFOUND.obj'
2>Done building project "example-app.vcxproj" -- FAILED.
我对这个错误感到非常惊讶,因为指定了 libtorch 路径并且 CMake 成功找到了它。
第三,构建Release成功,但是跳过了ALL_BUILD项目:
3>------ Skipped Build: Project: ALL_BUILD, Configuration: Release x64 ------
3>Project not selected to build for this solution configuration
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 1 skipped ==========
不确定应该选择哪种解决方案配置来构建所有这些。
如果您能澄清这些令人困惑的问题,我将不胜感激。
【问题讨论】:
标签: visual-studio cmake libtorch torchscript