1. 首先创建一个新环境名,注意不要指定python版本,后面安装pytorch会自动安装python
conda create --name detectron2
conda activate detectron2
2. 安装pytorch、torchvision
# CUDA 10.2
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=10.2 -c pytorch
# CUDA 11.1
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cudatoolkit=11.1 -c pytorch -c conda-forge
# CPU Only
conda install pytorch==1.8.0 torchvision==0.9.0 torchaudio==0.8.0 cpuonly -c pytorch
3. 安装opencv
pip install opencv-python==4.2.0.34
4. 安装cython
pip install cython
5. 安装pycocotools
pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
报错是网络原因 多尝试几次
6. detectron2安装
git clone https://github.com/facebookresearch/detectron2.git
进入网站
选择对应的版本,例如我是cuda10.2 torch1.8
python -m pip install detectron2 -f \
https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.8/index.html
之后环境就配好了
你的目录应该是这样的
上面这个是clone的上一级文件夹
下面detectron2是clone的
接下来进入detectron2测试
cd detectron2
7.测试
1)任选一张图片,放入detectron2的目录中
如图1.jpg
2)创建一个res的文件夹,查看结果
3)图有了 代码有了 环境有了 还差model
往下拉有
点进去Detectron2 Model Zoo
找到与configs匹配的model
比如我接下来要用的configs是mask_rcnn_R_50_FPN_1x.yaml
下载这个model
同样放入detectron2
最终输入
python demo/demo.py --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_1x.yaml --input 1.jpg --output res --opts MODEL.WEIGHTS model_final_a54504.pkl
到res中查看结果
本文为本人配环境过程
配置过程参考如下:
感谢阅读,如果有用记得给个大拇指