1. MMDetection簡介
MMdetection is an open source object detection toolbox based on PyTorch. It is a part of the open-mmlab project developed by Multimedia Laboratory, CUHK. 目前 Github 上只有 linux 版本代碼揖膜,下面內(nèi)容是將代碼移植到windows上的實現(xiàn)步驟沥割。
2. 配置環(huán)境
Windows10 + Cuda9 + PyTorch1.1
3. 所需文件
VC14編譯器敞曹, 百度網(wǎng)盤鏈接:https://pan.baidu.com/s/19ofabAeXW0XRB5XCXFwgDA 提取碼:oll5
4. 配置步驟和出現(xiàn)的問題
(1)安裝好Cuda環(huán)境豁鲤,這里不再贅述。
(2)安裝 VC14 編譯器 visualcppbuildtools_full.exe (上邊有百度云鏈接)眠冈,MMDetection大部分代碼用Python完成溅话,需要用編譯器將.cu文件編譯為.pyd文件。如果你已經(jīng)安裝VS2015或之上的版本专执,可以忽略這步。
(3)在系統(tǒng)變量Path 中添加 C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin
(4)下載安裝Anaconda3郁油,創(chuàng)建新環(huán)境后本股,安裝cython攀痊,我的新環(huán)境取名為open-mmlab
,以下步驟均在激活新環(huán)境下的CMD中執(zhí)行
conda install cython
(5) 下載mmdetection,并進入目錄
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
(6) 編譯roi_align的cuda拓展
cd mmdet/ops/roi_align
python setup.py build_ext --inplace
這里可能會報錯拄显,關(guān)于Half類型數(shù)據(jù)的運算符重載問題苟径,由于我并不經(jīng)常使用Half類型數(shù)據(jù),這里我直接將出錯文件的6行代碼注釋躬审,簡單粗暴棘街。注釋 anaconda3/your_env_name/titan_copy/lib/site-packages/torch/include\THC\THCNumerics.cuh
文件中的第191,192,193,194,195,197行。
(7) 編譯roi_pooling的cuda拓展
cd ../roi_pool
python setup.py build_ext --inplace
(8) 編譯nms的cuda拓展承边,修改mmdetection\mmdet\ops\nms下setup.py
文件遭殉,將第一行修改為第二行(第一行中compiler_so屬性為linux下gcc編譯器的屬性,windows下直接清空博助,這樣會默認使用VC14的默認屬性):
# default_compiler_so = self.compiler_so
default_compiler_so = ""
之后執(zhí)行
cd ../nms
python setup.py build_ext --inplace
(9) 編譯dcn的cuda拓展
cd ../dcn
python setup.py build_ext --inplace
(10) 編譯sigmoid_docal的cuda拓展,修改mmdetection\mmdet\ops\sigmoid_focal_loss\src
下的sigmoid_focal_loss_cuda.cu文件
1) 將文件中targets.contiguous().data<long>()
替換為 static_cast<long*>(targets.contiguous().data_ptr())
2) 在#include <cfloat>
之后添加函數(shù):
int Ceil_div(int a, int b) { return (a + b - 1); }
3) 將文件中兩處dim3 grid(std::min(THCCeilDiv(losses_size, 512L), 4096L));
替換為dim3 grid(std::min(Ceil_div((int)losses_size, 512), 4096))
;
之后執(zhí)行
cd ../sigmoid_focal_loss
python setup.py build_ext --inplace
(11) 編譯masked_conv的cuda拓展,修改mmdetection\mmdet\ops\masked_conv\src
下的masked_conv2d_kernel.cu
文件
將文件中
const long *mask_h_idx_ = mask_h_idx.data<long>();
const long *mask_w_idx_ = mask_w_idx.data<long>();
替換為
const long *mask_h_idx_ = static_cast<long*>(mask_h_idx.data_ptr());
const long *mask_w_idx_ = static_cast<long*>(mask_w_idx.data_ptr());
之后執(zhí)行
cd ../masked_conv
python setup.py build_ext --inplace
(12) 安裝pycocotools
pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
(13) 安裝mmdetection, cd到mmdetection根目錄
python setup.py develop
至此MMDetection在Windows下的配置完成恩沽,希望給希望能在Windows下運行MMDetection的小伙伴一些幫助。