win10下 detectron2 安裝
- 1. 安裝所需基礎環境
- 2. Win10下安裝方法及常見問題
1. 安裝所需基礎環境
github官方網址介紹的所需環境。同時也說明了了這個工具包并不完全支援windows系統,是以在win10上面安裝會遇到各種各樣的問題。當然,既然maskrcnn-benchmark可以安裝,這個工具包也可以進行安裝。首先除了系統外,其他的依賴項隻要按照官網上的建議安裝即可。但是,pycocotools卻不支援windows,是以直接pip安裝會出錯。關于這個工具庫的安裝,可借鑒[https://www.jianshu.com/p/8658cda3d553]
本方法中所用的環境具體配置為:
- Cuda 10.2 (cudnn 7.6.5)
- pytorch 1.5.0
- python 3.6.6
- Visual studio 19 (16.6.2)
- Gcc 8.1.0
- ninja 1.10.0
2. Win10下安裝方法及常見問題
① 首先需要先将detectron2 clone到本地
② 第二步,修改pytorch代碼。
外國友人提供的方法為:
但是,在實際的修改過程中會有些許差别,具體為:
(1) 第一個檔案的位置有變動為:{your evn path}\Lib\site-packages\torch\include\torch\csrc\jit\runtime\argumenta_spec.h
(2) 代碼改動位置應為161行,修改為 (其中注釋掉的為原來的代碼):
namespace {
//static constexpr size_t ARG_SPEC_DEPTH_LIMIT = 128;
static const size_t ARG_SPEC_DEPTH_LIMIT = 128;
}
(3) 另外,如果你使用的是中文版本的win10,還需要額外添加一步修改:
打開你環境下的cpp_extension.py, 找到如下代碼段的位置,在decode() 的括号中添加 ’ .gbk’ (注意.gbk前面有空格)
if sys.platform.startswith('darwin'):
# There is no particular minimum version we need for clang, so we're good here.
return True
try:
if sys.platform.startswith('linux'):
minimum_required_version = MINIMUM_GCC_VERSION
version = subprocess.check_output([compiler, '-dumpfullversion', '-dumpversion'])
version = version.decode(' gbk').strip().split('.')
else:
minimum_required_version = MINIMUM_MSVC_VERSION
compiler_info = subprocess.check_output(compiler, stderr=subprocess.STDOUT)
match = re.search(r'(\d+)\.(\d+)\.(\d+)', compiler_info.decode(' gbk').strip())
version = (0, 0, 0) if match is None else match.groups()
except Exception:
_, error, _ = sys.exc_info()
warnings.warn('Error checking compiler version for {}: {}'.format(compiler, error))
return False
③ 第三步,進行安裝
win10下安裝的步驟為:
(1) conda activate {your env}
(2) call “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat”
此處解決的問題為,如果不實作call一下本地的vs,會造成之後的安裝出現編譯器錯誤
(3) 上述兩個步驟進行完畢之後,安裝還是會出現錯誤,此時還需要修改detectron2下的代碼,具體為:
将detectron2\detectron2\layers\csrc\deformable 檔案夾下三個檔案中全部的 AT_CHECK 全部替換為 TORCH_CHECK (在不替換的情況下,會造成報錯,error: identifier “AT_CHECK” is undefined或者 CalledProcessError: Command ‘[‘ninja’, ‘-v’]’ returned non-zero exit status 1.)
另外,需要将檔案裡.cu檔案的的THCState_getCurrentStream(state) 替換為 at::cuda::getCurrentCUDAStream()
(4) 至此,win10下detectron安裝的準備工作完成,下一步直接安裝即可
cd detectron2
python setup.py build develop
(5) 安裝完成後可使用如下代碼,驗證是否安裝成功