1.首先安装anaconda,这个比较简单,网上很多教程
2.新建detectron环境
conda create --name detectron2 python=3.8
注意,这里的环境要求是根据detectron2的官方要求安装的,具体可以看detectron2/INSTALL.md at main · facebookresearch/detectron2 · GitHub
查看detectron环境
conda env list
3.安装Pytorch,这个参考官方网站Start Locally | PyTorch,选择conda版本,我这是linux、python3.8、cuda11.4、RTX3060显卡版本,会得到相应命令,装11.3就行(没有11.4版本)
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
查看Pytorch和TorchVision版本
python
import torch
torch.__version__
import torchvision
torch.vision.__version__
4.安装opencv
注意:opencv3已经不支持python3.8
python3.8版本直接通过conda安装就行
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python
5.安装cython和cocotools
pip install cython
pip install -U 'git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI'
6.检查
看一下上面安装的东西对不对
conda env list
7.安装配置detectron2
首先将源码克隆到本地
git clone https://github.com/facebookresearch/detectron2.git
也可以使用代理:https://ghproxy.com/
git clone https://ghproxy.com/https://github.com/facebookresearch/detectron2.git
8.安装detectron2
在detectron2上层目录执行
python -m pip install -e detectron2
9.数据集下载
官网地址:COCO - Common Objects in Context
百度网盘:链接: https://pan.baidu.com/s/1wad_82nFn8Pc_cQHnW3w_Q?pwd=nx76 提取码: nx76
10.解压数据集,并放入到/detectron2/datasets/
11.执行测试指令
注意:000000078548.jpg是你选择的图片,需要放在/detectron2/demo/文件夹下
python demo.py --config-file ../configs/COCO-Detection/retinanet_R_50_FPN_1x.yaml --input 000000078548.jpg [--other-options] --opts MODEL.WEIGHTS detectron2://COCO-Detection/retinanet_R_50_FPN_1x/190397773/model_final_bfca0b.pkl
12.执行训练指令
python ./tools/train_net.py --config-file ./configs/COCO-Detection/retinanet_R_50_FPN_1x.yaml --eval-only MODEL.WEIGHTS detectron2://COCO-Detection/retinanet_R_50_FPN_1x/190397773/model_final_bfca0b.pkl
13.其它问题
如果遇到了:执行detectron2编译报错No such file or directory: ‘/usr/local/cuda/bin/bin/nvcc‘
参考我这个博客:执行detectron2编译报错No such file or directory: ‘/usr/local/cuda/bin/bin/nvcc‘_C++有手就行的博客-CSDN博客