镜像选择
PyTorch 1.5.1
Python 3.8(ubuntu18.04)
Cuda 10.1
RTX 2080 Ti(11GB) * 1
环境配置
source activate
conda create -n open-mmlab python=3.7
conda activate open-mmlab
- pytorch安装,版本选择: pytorch
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.1 -c pytorch
- mmcv安装,根据cuda和torch版本选择命令:MMCV
python -c 'import torch;print(torch.__version__)'#查看torch和cuda版本
pip install mmcv==2.0.0rc4 -f https://download.openmmlab.com/mmcv/dist/cu117/torch1.13/index.html -i https://mirrors.aliyun.com/pypi/simple/
- mmdetection下载
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection/
pip install -r requirements.txt
pip install mmdet
- 建立work_dirs文件夹,将预训练模型上传
下载官方预训练模型
运行demo
- 方法一(命令试了好久,参考网上的命令怎么都不对,最后看了官方文档,发现是faster-rcnn和faster_rcnn的区别…我服了)
python demo/image_demo.py demo/demo.jpg configs/faster_rcnn/faster-rcnn_r101_fpn_1x_coco.py --weights preweights/faster_rcnn_r101_fpn_1x_coco_20200130-f513f705.pth --device cuda:0
检测结果在outputs文件夹中
- 方法二,新建py文件
from mmdet.apis import init_detector, inference_detector
config_file = 'configs/faster_rcnn/faster-rcnn_r101_fpn_1x_coco.py'
checkpoint_file = 'work_dirs/faster_rcnn_r101_fpn_1x_coco_20200130-f513f705.pth'
model = init_detector(config_file, checkpoint_file, device='cuda:0') # or device='cuda:0'
inference_detector(model, 'demo/demo.jpg')
没找到检测结果在哪
一些问题
- checkpoints文件建立后打不开
jupyter好像就是打不开,推测可能跟.ipynb_checkpoints隐藏文件有关
ls -a
rm -rf .ipynb_checkpoints
或rm -rf "find -type d -name .ipynb_checkpoints"
但还是没用,新建preweights文件夹存放预训练
2.
ValueError: Cannot find model: configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py in mmdet
image_demo.py: error: unrecognized arguments: checkpoints/faster_rcnn_r50_fpn
命令格式不对;py文件和预训练模型文件没有对应上
RuntimeError: unexpected EOF, expected 7219394 more bytes. The file might be corrupted.
预训练模型文件损坏,重新下载上传