-
创建虚拟环境
conda create -n detectron2 python=3.8 -y
-
激活环境
source activate detectron2
-
安装Pytorch1.9.0
根据CUDA版本选择对应的命令安装
# CUDA 11.1 pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html/whl/torch_stable.html # CUDA 10.2 pip install torch==1.9.0+cu102 torchvision==0.10.0+cu102 torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html # CPU only pip install torch==1.9.0+cpu torchvision==0.10.0+cpu torchaudio==0.9.0 -f https://download.pytorch.org/whl/torch_stable.html
-
安装Opencv
pip install opencv-python
-
安装pycocotools
pip install pycocotools
-
克隆仓库
git clone https://github.com/facebookresearch/detectron2.git
-
安装detectron2
根据自己安装的Pytorch、CUDA版本,选择对应的detectron2
版本安装# CUDA 11.1 python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu111/torch1.9/index.html # CUDA 10.2 python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cu102/torch1.9/index.html # CPU python -m pip install detectron2 -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/torch1.9/index.html
安装完成之后,到这里环境就配置好了,下载一张图片放到 detectron2 文件夹中,用于 检验环境是否安装成功
-
运行demo
# 打开终端,确人是否在 detectron2 的文件夹路径下 python demo/demo.py --config-file configs/COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml --input 1.jpg --output ./result.jpg --opts MODEL.WEIGHTS detectron2://COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x/137849600/model_final_f10217.pkl
注意:如果使用CPU运行,在最后面加上 MODEL.DEVICE cpu 即可
还有图片的路径,也要调整好
Detectron2安装教程
最新推荐文章于 2024-04-22 17:47:19 发布