凡是想在windows下从源码编译detectron2的,没有深厚的c++功底, 我劝你还是放弃吧. 改用Ubuntu 去编译轻松又方便.
昨天还能编译成功的, 今天就编译不成功了.
编译命令如下
git clone https://github.com/facebookresearch/detectron2.git
python -m pip install -e detectron2
结果报了一大堆的错误… 而且怎么都搜不到解决方案…
ERROR: Command errored out with exit status 1:
command: 'D:\Anaconda3\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'F:\\PySlowFast\\pyslowfast\\detectron2_repo\\setup.py'"'"'; __file__='"'"'F:\\PySlowFast\\pyslowfast\\detectron2_repo\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps
cwd: F:\PySlowFast\pyslowfast\detectron2_repo\
Complete output (47 lines):
No CUDA runtime is found, using CUDA_HOME='C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2'
running develop
running egg_info
writing detectron2.egg-info\PKG-INFO
writing dependency_links to detectron2.egg-info\dependency_links.txt
writing requirements to detectron2.egg-info\requires.txt
writing top-level names to detectron2.egg-info\top_level.txt
adding license file 'LICENSE' (matched pattern 'LICEN[CS]E*')
reading manifest file 'detectron2.egg-info\SOURCES.txt'
writing manifest file 'detectron2.egg-info\SOURCES.txt'
running build_ext
building 'detectron2._C' extension
Emitting ninja build file F:\PySlowFast\pyslowfast\detectron2_repo\build\temp.win-amd64-3.8\Release\build.ninja...
Compiling objects...
Allowing ninja to set a default number of workers... (overridable by setting the environment variable MAX_JOBS=N)
D:\Anaconda3\lib\site-packages\torch\utils\cpp_extension.py:294: UserWarning:
!! WARNING !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Your compiler (cl 19.00.24210) may be ABI-incompatible with PyTorch!
Please use a compiler that is ABI-compatible with GCC 5.0 and above.
See https://gcc.gnu.org/onlinedocs/libstdc++/manual/abi.html.
See https://gist.github.com/goldsborough/d466f43e8ffc948ff92de7486c5216d6
for instructions on how to install GCC 5 or higher.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! WARNING !!
warnings.warn(ABI_INCOMPATIBILITY_WARNING.format(compiler))
ninja: no work to do.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29910\bin\HostX86\x64\link.exe /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:D:\Anaconda3\lib\site-packages\torch\lib /LIBPATH:D:\Anaconda3\libs /LIBPATH:D:\Anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29910\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.28.29910\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.10240.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\8.1\lib\winv6.3\um\x64" c10.lib torch.lib torch_cpu.lib torch_python.lib /EXPORT:PyInit__C F:\PySlowFast\pyslowfast\detectron2_repo\build\temp.win-amd64-3.8\Release\PySlowFast\pyslowfast\detectron2_repo\detectron2\layers\csrc\vision.obj F:\PySlowFast\pyslowfast\detectron2_repo\build\temp.win-amd64-3.8\Release\PySlowFast\pyslowfast\detectron2_repo\detectron2\layers\csrc\box_iou_rotated\box_iou_rotated_cpu.obj F:\PySlowFast\pyslowfast\detectron2_repo\build\temp.win-amd64-3.8\Release\PySlowFast\pyslowfast\detectron2_repo\detectron2\layers\csrc\cocoeval\cocoeval.obj F:\PySlowFast\pyslowfast\detectron2_repo\build\temp.win-amd64-3.8\Release\PySlowFast\pyslowfast\detectron2_repo\detectron2\layers\csrc\nms_rotated\nms_rotated_cpu.obj F:\PySlowFast\pyslowfast\detectron2_repo\build\temp.win-amd64-3.8\Release\PySlowFast\pyslowfast\detectron2_repo\detectron2\layers\csrc\ROIAlignRotated\ROIAlignRotated_cpu.obj /OUT:build\lib.win-amd64-3.8\detectron2\_C.cp38-win_amd64.pyd /IMPLIB:F:\PySlowFast\pyslowfast\detectron2_repo\build\temp.win-amd64-3.8\Release\PySlowFast\pyslowfast\detectron2_repo\detectron2\layers\csrc\_C.cp38-win_amd64.lib
正在创建库 F:\PySlowFast\pyslowfast\detectron2_repo\build\temp.win-amd64-3.8\Release\PySlowFast\pyslowfast\detectron2_repo\detectron2\layers\csrc\_C.cp38-win_amd64.lib 和对象 F:\PySlowFast\pyslowfast\detectron2_repo\build\temp.win-amd64-3.8\Release\PySlowFast\pyslowfast\detectron2_repo\detectron2\layers\csrc\_C.cp38-win_amd64.exp
vision.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) struct c10::FunctionSchema __cdecl c10::detail::infer_schema::make_function_schema(class c10::ArrayRef<struct c10::detail::infer_schema::ArgumentDef>,class c10::ArrayRef<struct c10::detail::infer_schema::ArgumentDef>)" (__imp_?make_function_schema@infer_schema@detail@c10@@YA?AUFunctionSchema@3@V?$ArrayRef@UArgumentDef@infer_schema@detail@c10@@@3@0@Z)
vision.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) void __cdecl c10::detail::torchCheckFail(char const *,char const *,unsigned int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &)" (__imp_?torchCheckFail@detail@c10@@YAXPEBD0IAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
vision.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) private: void __cdecl c10::IValue::moveFrom(struct c10::IValue &&)" (__imp_?moveFrom@IValue@c10@@AEAAX$$QEAU12@@Z)
vision.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) private: void __cdecl c10::IValue::destroy(void)" (__imp_?destroy@IValue@c10@@AEAAXXZ)
box_iou_rotated_cpu.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) class at::Tensor __cdecl at::empty(class c10::ArrayRef<__int64>,struct c10::TensorOptions,class c10::optional<enum c10::MemoryFormat>)" (__imp_?empty@at@@YA?AVTensor@1@V?$ArrayRef@_J@c10@@UTensorOptions@4@V?$optional@W4MemoryFormat@c10@@@4@@Z)
nms_rotated_cpu.obj : error LNK2001: 无法解析的外部符号 "__declspec(dllimport) class at::Tensor __cdecl at::zeros(class c10::ArrayRef<__int64>,struct c10::TensorOptions)" (__imp_?zeros@at@@YA?AVTensor@1@V?$ArrayRef@_J@c10@@UTensorOptions@4@@Z)
build\lib.win-amd64-3.8\detectron2\_C.cp38-win_amd64.pyd : fatal error LNK1120: 6 个无法解析的外部命令
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.28.29910\\bin\\HostX86\\x64\\link.exe' failed with exit status 1120
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
File "D:\Anaconda3\lib\site-packages\colorama\ansitowin32.py", line 59, in closed
return stream.closed
ValueError: underlying buffer has been detached
后来实在不知道怎么搞了. 就试着把build目录下的文件全删掉了.然后重新编译.
TMD ,竟然好了. 提示success. 也没报什么错误.
然后运行后面的识别命令发现还是不能够找到包 detectron2.layers
发现错误中有提到ninja, 于是顺手装了一下命令如下.
python -m pip install ninja
再次编译
python -m pip install -e detectron2
还是一堆的错误, 内容一样.
看样子应该是执行 ninja -v这个命令的时候出问题了.
我自己在命令行里运行这个命令的时候 发现是找不到这个ninja命令的.
于是我从官网下载了一个 ninja 地址: https://github.com/ninja-build/ninja/releases
放到我的项目detectron2 根目录下. 确保 这个命令能别执行到
将 D:\Anaconda3\Lib\site-packages\torch\utils\cpp_extension.py :363行
self.use_ninja = kwargs.get('use_ninja', True)
改成
self.use_ninja = kwargs.get('use_ninja', False)
6月3日,
昨天郁闷了一天, 没头绪, 啥玩意都解决不了… 换了个命令.
cd detectron2
python setup.py build --force develop
注意后面有个参数develop, 这个参数可以显示详细的信息
C++为啥这么恶心呢? 为啥一定要编译呢??凡是编译的就没有一次顺顺利利的. 烦死了, 浪费我生命.
不能搞个中间语言么? 每次运行的时候先编译成本机语言. 这样就不怕机器和移植了.
最后放弃了, detectron2 对linux支持的比较好. 对window支持的不是很好.
考虑到我对c++不是很精通,也没这么多精力去折腾这玩意.
最后放弃了.
再见 detectron2