mmdetection在windows10系統環境中搭建

mmdetection官方並不提供windows版本的穩定安裝教程,網上有相關的教程但是並不支持最新的mmdetection版本,這邊根據各位大佬的博客總結了以下這篇文章,幫助大家可以在windows10中使用。

環境版本要求:

python=3.6

cuda=10.0

cudnn=7.5.0

pytorch=1.2.0

torchversion=0.4.0

安裝軟件:

安裝vs2017

需要勾選c++環境,給mmdetection編譯提供環境

安裝cuda10

安裝時有關vs的相關選項需要選中

注意:如果是安裝cuda9的話不支持最新的1917版本的vs2017,只能支持到1911版本的vs2017,所以可以安裝vs2015

安裝cudnn7.5.0

將壓縮包中所有的文件夾直接複製粘貼到cuda安裝目錄下即可

安裝anaconda

官網下載最新版本默認安裝即可,需要提升anaconda文件夾權限爲完全控制

安裝pycharm

安裝gitbash

從github上下載項目以及安裝pycocotools都需要用到

下載地址:https://gitforwindows.org/

 

python環境搭建:

以管理員身份運行Anaconda Prompt(windows安裝一定要以管理員身份安裝,不然有些東西會裝不上去,沒有權限)

創建python3.6環境:

conda create -n mmdetecion python=3.6

(python3.7兼容性不好)

激活環境:

conda activate mmdetection

安裝pytorch,window環境下穩定1.2.0版本:

conda install pytorch torchvision cudatoolkit=10.0 -c pytorch

conda國內加速教程:https://segmentfault.com/a/1190000019680625

安裝mmcv:

官方下載地址:https://github.com/open-mmlab/mmcv

git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
pip install -e .

會自動安裝Cython

安裝pycocotools:

是mmdection讀取coco數據集必備包

在命令行輸入

pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI

安裝mmdetection:

官方網站:https://github.com/open-mmlab/mmdetection

git clone https://github.com/open-mmlab/mmdetection.git

cd mmdetection

補充安裝依賴包requirements:

pip install -r requirements.txt

 

修改編譯文件:

1.將~Lib\site-packages\torch\utils\cpp_extension.py 中 info = info.decode().lower()修爲 info=info.decode("utf8","ignore").lower()

最好將所有decode() 都改成decode("utf8","ignore")

修改setup.py文件中extra_compile_args 相關代碼,增加cxx的:"-DMS_WIN64","-MD"

def make_cuda_ext(name, module, sources):

    return CUDAExtension(
        name='{}.{}'.format(module, name),
        sources=[os.path.join(*module.split('.'), p) for p in sources],
        extra_compile_args={
            'cxx': ["-DMS_WIN64","-MD"],
            'nvcc': [
                '-D__CUDA_NO_HALF_OPERATORS__',
                '-D__CUDA_NO_HALF_CONVERSIONS__',
                '-D__CUDA_NO_HALF2_OPERATORS__',
            ]
        })

2.當前文件夾運行

python setup.py build_ext --inplace 進行編譯

python setup.py install develop 完成安裝

運行pip list 查看是否安裝成功,成功的話會有mmdet包以及對應版本

後續問題:

修改~\Lib\site-packages\mmcv\utils中的config.py文件中的123行的

with open(filename, 'r', encoding='utf-8') as f:

增加encoding='utf-8'

 

到此,在windows10中就可以正常運行mmdetecion框架代碼了,之前有遇到focal loss不能正常使用,但是後來安裝都是可以的,後續有什麼問題歡迎大家提出,謝謝。

 

2020-01-10更新:

mmdetection在2019年12月13號進行了新版本的更新,其中對api/train.py增加torch.distributed,這塊在windows下不支持,所以要在windows中訓練的話需要把v1.0rc1的版本的train與新版本的train進行合併,主要是去除torch.distributed以及_non_dist_train的修改爲主。

文件見下載。

參考文章:

https://zhuanlan.zhihu.com/p/55789320

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章