配置环境
Step 1. Create a conda environment and activate it.
conda create --name openmmlab python=3.8 -y conda activate openmmlab
Step 2. Install PyTorch following official instructions, e.g.
On GPU platforms:
conda install pytorch torchvision -c pytorch ( 也可以pip安装,pip install torch==1.8.1+cu101 torchvision==0.9.1+cu101 torchaudio==0.8.1 -f https://download.pytorch.org/whl/torch_stable.html)
On CPU platforms:
conda install pytorch torchvision cpuonly -c pytorch
安装
Step 0. Install MMCV using MIM.
pip install -U openmim
mim install mmcv-full==1.5.0 (版本必须在[1.3.17,1.5.0]区间内)
Step 1. Install MMDetection.
Case a: If you develop and run mmdet directly, install it from source:
git clone https://github.com/open-mmlab/mmdetection.git cd mmdetection pip install -v -e . # "-v" means verbose, or more output # "-e" means installing a project in editable mode, # thus any local modifications made to the code will take effect without reinstallation.
Case b: If you use mmdet as a dependency or third-party package, install it with pip:
pip install mmdet
pip install mmcv==1.5.0 (与mmcv-full一致,版本必须在[1.3.17,1.5.0]区间内)
Verify the installation
To verify whether MMDetection is installed correctly, we provide some sample codes to run an inference demo.
Step 1. We need to download config and checkpoint files.
mim download mmdet --config yolov3_mobilenetv2_320_300e_coco --dest .
The downloading will take several seconds or more, depending on your network environment. When it is done, you will find two files yolov3_mobilenetv2_320_300e_coco.py
and yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth
in your current folder.
Step 2. Verify the inference demo.
Option (a). If you install mmdetection from source, just run the following command.
python demo/image_demo.py demo/demo.jpg yolov3_mobilenetv2_320_300e_coco.py yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth --device cpu --out-file result.jpg
You will see a new image result.jpg
on your current folder, where bounding boxes are plotted on cars, benches, etc.
Option (b). If you install mmdetection with pip, open you python interpreter and copy&paste the following codes.
from mmdet.apis import init_detector, inference_detector config_file = 'yolov3_mobilenetv2_320_300e_coco.py' checkpoint_file = 'yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth' model = init_detector(config_file, checkpoint_file, device='cpu') # or device='cuda:0' inference_detector(model, 'demo/cat.jpg')
在环境中导入from mmcv.ops import RoIPool 不报错,则问题解决,否则重装mmcv-full 和 mmvc
mim uninstall mmcv-full
mim install mmcv-full==1.5.0
pip uninstall mmcv
pip install mmcv==1.5.0