|
| 1 | +## Prerequisites |
| 2 | + |
| 3 | +- Linux or macOS (Windows is in experimental support) |
| 4 | +- Python 3.6+ |
| 5 | +- PyTorch 1.3+ |
| 6 | +- CUDA 9.2+ (If you build PyTorch from source, CUDA 9.0 is also compatible) |
| 7 | +- GCC 5+ |
| 8 | +- [MMCV](https://mmcv.readthedocs.io/en/latest/#installation) |
| 9 | + |
| 10 | +The compatible MMDetection and MMCV versions are as below. Please install the correct version of MMCV to avoid installation issues. |
| 11 | + |
| 12 | +| MMDetection version | MMCV version | |
| 13 | +|:-------------------:|:-------------------:| |
| 14 | +| master | mmcv-full>=1.1.5, <1.3| |
| 15 | +| 2.7.0 | mmcv-full>=1.1.5, <1.3| |
| 16 | +| 2.6.0 | mmcv-full>=1.1.5, <1.3| |
| 17 | +| 2.5.0 | mmcv-full>=1.1.5, <1.3| |
| 18 | +| 2.4.0 | mmcv-full>=1.1.1, <1.3| |
| 19 | +| 2.3.0 | mmcv-full==1.0.5| |
| 20 | +| 2.3.0rc0 | mmcv-full>=1.0.2 | |
| 21 | +| 2.2.1 | mmcv==0.6.2 | |
| 22 | +| 2.2.0 | mmcv==0.6.2 | |
| 23 | +| 2.1.0 | mmcv>=0.5.9, <=0.6.1| |
| 24 | +| 2.0.0 | mmcv>=0.5.1, <=0.5.8| |
| 25 | + |
| 26 | +Note: You need to run `pip uninstall mmcv` first if you have mmcv installed. |
| 27 | +If mmcv and mmcv-full are both installed, there will be `ModuleNotFoundError`. |
| 28 | + |
| 29 | +## Installation |
| 30 | + |
| 31 | +1. Create a conda virtual environment and activate it. |
| 32 | + |
| 33 | + ```shell |
| 34 | + conda create -n open-mmlab python=3.7 -y |
| 35 | + conda activate open-mmlab |
| 36 | + ``` |
| 37 | + |
| 38 | +2. Install PyTorch and torchvision following the [official instructions](https://pytorch.org/), e.g., |
| 39 | + |
| 40 | + ```shell |
| 41 | + conda install pytorch torchvision -c pytorch |
| 42 | + ``` |
| 43 | + |
| 44 | + Note: Make sure that your compilation CUDA version and runtime CUDA version match. |
| 45 | + You can check the supported CUDA version for precompiled packages on the [PyTorch website](https://pytorch.org/). |
| 46 | + |
| 47 | + `E.g.1` If you have CUDA 10.1 installed under `/usr/local/cuda` and would like to install |
| 48 | + PyTorch 1.5, you need to install the prebuilt PyTorch with CUDA 10.1. |
| 49 | + |
| 50 | + ```shell |
| 51 | + conda install pytorch cudatoolkit=10.1 torchvision -c pytorch |
| 52 | + ``` |
| 53 | + |
| 54 | + `E.g. 2` If you have CUDA 9.2 installed under `/usr/local/cuda` and would like to install |
| 55 | + PyTorch 1.3.1., you need to install the prebuilt PyTorch with CUDA 9.2. |
| 56 | + |
| 57 | + ```shell |
| 58 | + conda install pytorch=1.3.1 cudatoolkit=9.2 torchvision=0.4.2 -c pytorch |
| 59 | + ``` |
| 60 | + |
| 61 | + If you build PyTorch from source instead of installing the prebuilt pacakge, |
| 62 | + you can use more CUDA versions such as 9.0. |
| 63 | + |
| 64 | +3. Install mmcv-full, we recommend you to install the pre-build package as below. |
| 65 | + |
| 66 | + ```shell |
| 67 | + pip install mmcv-full==latest+torch1.6.0+cu101 -f https://download.openmmlab.com/mmcv/dist/index.html |
| 68 | + ``` |
| 69 | + |
| 70 | + See [here](https://github.com/open-mmlab/mmcv#install-with-pip) for different versions of MMCV compatible to different PyTorch and CUDA versions. |
| 71 | + Optionally you can choose to compile mmcv from source by the following command |
| 72 | + |
| 73 | + ```shell |
| 74 | + git clone https://github.com/open-mmlab/mmcv.git |
| 75 | + cd mmcv |
| 76 | + MMCV_WITH_OPS=1 pip install -e . # package mmcv-full will be installed after this step |
| 77 | + cd .. |
| 78 | + ``` |
| 79 | + |
| 80 | + Or directly run |
| 81 | + |
| 82 | + ```shell |
| 83 | + pip install mmcv-full |
| 84 | + ``` |
| 85 | + |
| 86 | +4. Clone the MMDetection repository. |
| 87 | + |
| 88 | + ```shell |
| 89 | + git clone https://github.com/open-mmlab/mmdetection.git |
| 90 | + cd mmdetection |
| 91 | + ``` |
| 92 | + |
| 93 | +5. Install build requirements and then install MMDetection. |
| 94 | + |
| 95 | + ```shell |
| 96 | + pip install -r requirements/build.txt |
| 97 | + pip install -v -e . # or "python setup.py develop" |
| 98 | + ``` |
| 99 | + |
| 100 | +Note: |
| 101 | + |
| 102 | +a. Following the above instructions, MMDetection is installed on `dev` mode |
| 103 | +, any local modifications made to the code will take effect without the need to reinstall it. |
| 104 | + |
| 105 | +b. If you would like to use `opencv-python-headless` instead of `opencv |
| 106 | +-python`, |
| 107 | +you can install it before installing MMCV. |
| 108 | + |
| 109 | +c. Some dependencies are optional. Simply running `pip install -v -e .` will |
| 110 | + only install the minimum runtime requirements. To use optional dependencies like `albumentations` and `imagecorruptions` either install them manually with `pip install -r requirements/optional.txt` or specify desired extras when calling `pip` (e.g. `pip install -v -e .[optional]`). Valid keys for the extras field are: `all`, `tests`, `build`, and `optional`. |
| 111 | + |
| 112 | +### Install with CPU only |
| 113 | + |
| 114 | +The code can be built for CPU only environment (where CUDA isn't available). |
| 115 | +
|
| 116 | +In CPU mode you can run the demo/webcam_demo.py for example. |
| 117 | +However some functionality is gone in this mode: |
| 118 | +
|
| 119 | +- Deformable Convolution |
| 120 | +- Deformable ROI pooling |
| 121 | +- CARAFE: Content-Aware ReAssembly of FEatures |
| 122 | +- nms_cuda |
| 123 | +- sigmoid_focal_loss_cuda |
| 124 | +
|
| 125 | +So if you try to run inference with a model containing deformable convolution you will get an error. |
| 126 | +
|
| 127 | +### Another option: Docker Image |
| 128 | +
|
| 129 | +We provide a [Dockerfile](https://github.com/open-mmlab/mmdetection/blob/master/docker/Dockerfile) to build an image. Ensure that you are using [docker version](https://docs.docker.com/engine/install/) >=19.03. |
| 130 | +
|
| 131 | +```shell |
| 132 | +# build an image with PyTorch 1.6, CUDA 10.1 |
| 133 | +docker build -t mmdetection docker/ |
| 134 | +``` |
| 135 | +
|
| 136 | +Run it with |
| 137 | +
|
| 138 | +```shell |
| 139 | +docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmdetection/data mmdetection |
| 140 | +``` |
| 141 | +
|
| 142 | +### A from-scratch setup script |
| 143 | +
|
| 144 | +Assuming that you already have CUDA 10.1 installed, here is a full script for setting up MMDetection with conda. |
| 145 | +
|
| 146 | +```shell |
| 147 | +conda create -n open-mmlab python=3.7 -y |
| 148 | +conda activate open-mmlab |
| 149 | +
|
| 150 | +conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1 -c pytorch -y |
| 151 | +
|
| 152 | +# install the latest mmcv |
| 153 | +pip install mmcv-full==latest+torch1.6.0+cu101 -f https://download.openmmlab.com/mmcv/dist/index.html |
| 154 | +
|
| 155 | +# install mmdetection |
| 156 | +git clone https://github.com/open-mmlab/mmdetection.git |
| 157 | +cd mmdetection |
| 158 | +pip install -r requirements/build.txt |
| 159 | +pip install -v -e . |
| 160 | +``` |
| 161 | +
|
| 162 | +### Developing with multiple MMDetection versions |
| 163 | +
|
| 164 | +The train and test scripts already modify the `PYTHONPATH` to ensure the script use the MMDetection in the current directory. |
| 165 | +
|
| 166 | +To use the default MMDetection installed in the environment rather than that you are working with, you can remove the following line in those scripts |
| 167 | +
|
| 168 | +```shell |
| 169 | +PYTHONPATH="$(dirname $0)/..":$PYTHONPATH |
| 170 | +``` |
| 171 | +
|
| 172 | +## Verification |
| 173 | +
|
| 174 | +To verify whether MMDetection and the required environment are installed correctly, we can run sample python codes to initialize a detector and inference a demo image: |
| 175 | +
|
| 176 | +```python |
| 177 | +from mmdet.apis import init_detector, inference_detector |
| 178 | +
|
| 179 | +config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py' |
| 180 | +device = 'cuda:0' |
| 181 | +# init a detector |
| 182 | +model = init_detector(config_file, device=device) |
| 183 | +# inference the demo image |
| 184 | +inference_detector(model, 'demo/demo.jpg') |
| 185 | +``` |
| 186 | +
|
| 187 | +The above code is supposed to run successfully upon you finish the installation. |
0 commit comments