win10、7安装Detectron2
Requirements
- Python >= 3.6(Conda)
- PyTorch==1.7
- torchvision==0.8.1
- python opencv
- fvcore: pip install git+https://github.com/facebookresearch/fvcore
- pycocotools: pip install cython; pip install git+https://github.com/philferriere/cocoapi.git#subdirectory=PythonAPI
- VS2019(no test in older version)
- CUDA10.1(no test in older version)
修改源码
可以使用以下的脚本文件进行修改源文件,将SITE修改成你电脑的conda路径,也可以手动改源文件
#!/bin/bash
SITE=/mnt/c/Users/thomas.jungblut/AppData/Local/Programs/Python/Python37/Lib/site-packages
sed -i.bak -e 's/CONSTEXPR_EXCEPT_WIN_CUDA/const/g' "${SITE}/torch/include/torch/csrc/jit/api/module.h"
sed -i.bak -e 's/return \*(this->value)/return \*((type\*)this->value)/g' "${SITE}/torch/include/pybind11/cast.h"
sed -i.bak '/static constexpr Symbol Kind/d' "${SITE}/torch/include/torch/csrc/jit/ir/ir.h"
- 找到conda中对应的文件夹/Lib/site-packages
- 修改该文件夹下三个路径中对应的源文件
# 需要手动修改的三个源文件
# /torch/include/torch/csrc/jit/api/module.h
# 将这个头文件中 CONSTEXPR_EXCEPT_WIN_CUDA 全部替换为const
# /torch/include/pybind11/cast.h
# 将这个头文件中 explicit operator type&() { return *(this->value);} 改为 explicit operator type&() { return *((type*)this->value);}
# /torch/include/torch/csrc/jit/ir/ir.h
# 将这个头文件中的两处 static constexpr Symbol Kind 语句注释掉
编译
在cmd中运行以下命令
conda activate {your env}
# 企业版、社区版和专业版路径有所差异,具体自己安装的版本来选择
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars64.bat"
SET DISTUTILS_USE_SDK=1
git clone https://github.com/facebookresearch/detectron2
cd detectron2
python setup.py build develop
测试
- 环境测试
- demo测试
# 将一张图片复制到detectron2根目录下,cmd运行以下命令
python demo/demo.py --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --input ./1.png --output ./out.png --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl
# 需要外网下载模型,不FQ很慢
- 测试结果
参考链接:
- https://github.com/conansherry/detectron2 # 注:这个链接是win10,pytorch1.30安装detectron2
- https://github.com/facebookresearch/detectron2
- https://github.com/flatironinstitute/CaImAn/issues/418
- https://github.com/facebookresearch/detectron2/issues/9