下载libtorch
遇到错误
解决方法,
https://github.com/pytorch/pytorch/issues/24308
ivalue.h文件中把下面这段
template<class Key, class Value>
/// \cond DOXYGEN_CANNOT_HANDLE_CONSTRUCTORS_WITH_MACROS_SO_EXCLUDE_THIS_LINE_FROM_DOXYGEN
C10_DEPRECATED_MESSAGE("IValues based on std::unordered_map are slow and deprecated. Please use c10::Dict instead." )
/// \endcond
IValue(std::unordered_map<Key, Value> v);
改为
template<class Key, class Value>
IValue(std::unordered_map<Key, Value> v);
在头文件中加入,或者主函数前
#undef slots
#include "torch/script.h"
#define slots Q_SLOTS
就解决了。
qt的pro文件:
QMAKE_CXXFLAGS -= /permissive- CONFIG += no_keywords QMAKE_CXXFLAGS += -DGLIBCXX_USE_CXX11_ABI=0
INCLUDEPATH+=E:/software/libtorch_debug/include\
E:/software/libtorch_debug/include/torch/csrc/api/include
DEPENDPATH+=E:/software/libtorch_debug/include\
E:/software/libtorch_debug/include/torch/csrc/api/include
LIBS += -LE:/software/libtorch_debug/lib -lc10_cuda -lc10d \#-lc10
-lasmjit \
-lcaffe2_detectron_ops_gpu \
-lcaffe2_module_test_dynamic \
-lcaffe2_nvrtc \
-lclog -lcpuinfo\
-ldnnl -lfbgemm\
-lgloo -lgloo_cuda\
-llibprotocd \
# -llibprotobufd -llibprotobuf-lited
-lmkldnn\
-ltorch_cpu \#-ltorch -ltorch_cuda
但之后可能还会有错误,笔者的release/debug版本过了,
但还是用不了GPU,希望后续有大佬可以解决如何配置GPU版本的办法把
参考:
Setting up a C++ project in Visual Studio 2019 with LibTorch 1.6
需要添加的lib列表:
CPU Version: torch_cpu.lib, c10.lib, torch.lib
GPU Version: torch.lib, torch_cuda.lib, caffe2_nvrtc.lib, c10.lib, c10_cuda.lib, torch_cpu.lib, -INCLUDE:?warp_size@cuda@at@@YAHXZ
参考网站:(https://github.com/pytorch/pytorch/issues/31611#issuecomment-594383154)
QT的GPU版本主要是少了最后这个链接器选项:-INCLUDE:?warp_size@cuda@at@@YAHXZ
这个-INCLUDE参数主要是对链接器添加符号的引用。不知道QT如何增加这个参数,如果有大佬知道希望告诉小弟!