ubantu下mmdetection安装
1.安装anaconda(注意对应的python版本即可)
安装mmdetection(主要参照github上官方代码)
1.首先先进行换源,在创建anaconda虚拟环境之前(创建虚拟环境之后再换原下载速度很慢,不知道为什么,如果创建新环境失败:conda clean -t
意思是需要清除之前的缓存,也可能与使用的源有关系)。
2.注意命令是在哪个目录下运行(你需要哪个版本就指定好版本,注意各版本之间的依赖关系)
conda create -n mmdet1 python=3.7 -y
conda activate mmdet1
conda install pytorch1.6.0 torchvision0.7.0 cudatoolkit=10.2 -c pytorch
pip install mmcv-full==1.3.8 -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.6.0/index.html
git clone https://github.com/open-mmlab/mmdetection.git
或者 pip install mmdet
cd mmdetection
pip install -r requirements/build.txt
python setup.py develop # 对mmdet进行编译,当你修改mmdet版本或修改其他包的版本后,要重新编译一次
3.创建文件夹checkpoints,并把下载的预训练模型放在其中,下载地址http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth.
2)运行demo代码(注意在demo文件下新建立test_mmdetection.py):
在安装之后,首先要进行验证是否安装成功,在mmdetection的文件夹下有一demo目录,其中有一张图片,首先新建checkpoints文件夹,下载 https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth 训练好的rcnn模型,放入checkpoints文件夹中,可以执行以下代码进行测试
from mmdet.apis import init_detector, inference_detector, show_result_pyplot
import mmcv
config_file = '../configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
checkpoint_file = '../checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')
# test a single image
img = 'demo.jpg'
result = inference_detector(model, img)
# show the results
show_result_pyplot(model, img, result)
结果展示
参考博文
https://blog.csdn.net/qq_41917697/article/details/114899523
https://blog.csdn.net/qq_40608730/article/details/118154400