计算机视觉 | mmdetection框架学习

[框架官网]:(https://github.com/open-mmlab/mmdetection)

### 软件环境
* Python 3.7
* PyTorch 1.1 and (CUDA 9.0 or higher)
* NCCL 2(多GPU间的通信,可不安装)
* GCC 4.9 or higher ([非root权限下配置自己的GCC版本](https://gitlab.gridsum.com/research/team/dl-server/issues/57))
* mmcv (`pip install mmcv`)
### 创建虚拟环境
* conda create -n open-mmlab python=3.7 -y
* conda activate open-mmlab
### 安装Pytorch 1.1与 CUDA
### CUDA 9.0
* conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=9.0 -c pytorch


### CUDA 10.0
* conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0 -c pytorch


### CPU Only
* conda install pytorch-cpu==1.1.0 torchvision-cpu==0.3.0 cpuonly -c pytorch
### 拉取mmdetection仓库
* git clone https://github.com/open-mmlab/mmdetection.git
* cd mmdetection  
### 安装依赖项
* pip install -r requirements/build.txt
* pip install "git+https://github.com/cocodataset/cocoapi.git#subdirectory=PythonAPI"
* pip install -v -e .
* pip install -r requirements/optional.txt
* pip install -r requirements/tests.txt

mmdetection demo代码运行

from mmdet.apis import init_detector, inference_detector, show_result
import mmcv


config_file = '/data/wangzhili/mmdetection/configs/faster_rcnn_r101_fpn_1x.py'
checkpoint_file = '/data/wangzhili/mmdetection/checkpoint/faster_rcnn_r101_fpn_1x_20181129-d1468807.pth'


# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:1')


# test a single image and show the results
img = '/data/wangzhili/mmdetection/demo/coco_test_12510.jpg'  # or img = mmcv.imread(img), which will only load it once
result = inference_detector(model, img)
# visualize the results in a new window
# show_result(img, result, model.CLASSES)
# or save the visualization results to image files
# show_result(img, result, model.CLASSES, out_file='result.jpg')
print('done')


# test a video and show the results
video = mmcv.VideoReader('/data/wangzhili/mmdetection/demo/1a9a369b-a436-4ea2-96cb-24ad5416f29a.mp4')
for frame in video:
    result = inference_detector(model, frame)
    print('done')
    # show_result(frame, result, model.CLASSES, wait_time=1)


下载模型网址与替换阿里云下载链接

* [model zoo](https://mmdetection.readthedocs.io/en/latest/MODEL_ZOO.html#environment)
* replace `https://s3.ap-northeast-2.amazonaws.com/open-mmlab` with `https://open-mmlab.oss-cn-beijing.aliyuncs.com `in model urls.

你可能感兴趣的:(计算机视觉 | mmdetection框架学习)