参考文档:https://mmdetection.readthedocs.io/en/latest/get_started.html
安装过程中,版本需要对应,否则会出现问题。
MMDetection和MMVC对应版本如下:(使用MMDetection2.7.0 mmcv-full1.1.5)
https://github.com/open-mmlab/mmdetection/releases/tag/v2.7.0
MMDetection version | MMCV version |
---|---|
master | mmcv-full>=1.2.4, <1.3 |
2.8.0 | mmcv-full>=1.2.4, <1.3 |
2.7.0 | mmcv-full>=1.1.5, <1.3 |
2.6.0 | mmcv-full>=1.1.5, <1.3 |
2.5.0 | mmcv-full>=1.1.5, <1.3 |
2.4.0 | mmcv-full>=1.1.1, <1.3 |
2.3.0 | mmcv-full==1.0.5 |
2.3.0rc0 | mmcv-full>=1.0.2 |
2.2.1 | mmcv==0.6.2 |
2.2.0 | mmcv==0.6.2 |
2.1.0 | mmcv>=0.5.9, <=0.6.1 |
2.0.0 | mmcv>=0.5.1, <=0.5.8 |
使用conda 创建虚拟环境并激活虚拟环境。
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab
安装pytorch
Pytorch官网:https://pytorch.org/get-started/locally/
pip install torch==1.6.0+cu101 torchvision==0.7.0+cu101 -f https://download.pytorch.org/whl/torch_stable.html
安装mmcv-full:
pip install mmcv-full==1.1.5 -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.6.0/index.html
Clone the MMDetection repository:
github地址:https://github.com/open-mmlab/mmdetection(可以进入github选择合适的版本下载)
mmdetection2.7.0(含有faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth) 百度网盘:https://pan.baidu.com/s/1stnGtsRZb4WrB2qws3jFhQ 提取码:etu7
下面的命令可以忽略:
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
安装MMDetection
pip install -r requirements/build.txt
python setup.py develop
安装成功!!
如果安装过程出现下面问题:
则在setup中添加一行代码:
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"
mmdetection 文件夹下 demo文件夹下含有测试代码:
还需要安装pycocotools(需要vc环境,可以参考博客:https://www.jianshu.com/p/8658cda3d553)、scipy、matplotlib(使用pip安装即可)
pip install mmpycocotools(安装mmpycocotools)
https://github.com/philferriere/cocoapi下载源码,并进行解压。
以管理员身份打开 CMD 终端,并切换到 cocoapi\PythonAPI
目录。运行以下指令:
python setup.py build_ext install
测试是否安装成功:
下载checkpoints文件,并放到checkpoints文件夹下:
# download the checkpoint from model zoo and put it in `checkpoints/`
# url: http://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
mmdetection-2.7.0文件夹下demo中含有测试代码:(包含图片检测 image_demo.py 和调用摄像头检测 webcam_demo.py)
image_demo.py使用命令运行:
python demo\image_demo.py demo\demo.jpg configs\faster_rcnn\faster_rcnn_r50_fpn_1x_coco.py checkpoints\faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
测试结果:
换张图片试一下:
webcam_demo.py 使用命令运行:
python demo\webcam_demo.py configs\faster_rcnn\faster_rcnn_r50_fpn_1x_coco.py checkpoints\faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
运行结果:
代码结构图:
下图来源:https://www.cnblogs.com/wjy-lulu/p/13268321.html(如有侵权,联系删除!)