windows10、7 Detectron2安装+测试

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"
  1. 找到conda中对应的文件夹/Lib/site-packages
  2. 修改该文件夹下三个路径中对应的源文件
# 需要手动修改的三个源文件

# /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很慢
  1. 测试结果
    测试结果
参考链接:
  • 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值