You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

get_started.md 10 kB

2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. ## Prerequisites
  2. - Linux or macOS (Windows is in experimental support)
  3. - Python 3.6+
  4. - PyTorch 1.3+
  5. - CUDA 9.2+ (If you build PyTorch from source, CUDA 9.0 is also compatible)
  6. - GCC 5+
  7. - [MMCV](https://mmcv.readthedocs.io/en/latest/#installation)
  8. Compatible MMDetection and MMCV versions are shown as below. Please install the correct version of MMCV to avoid installation issues.
  9. | MMDetection version | MMCV version |
  10. |:-------------------:|:-------------------:|
  11. | master | mmcv-full>=1.3.14, <1.4.0 |
  12. | 2.18.0 | mmcv-full>=1.3.14, <1.4.0 |
  13. | 2.17.0 | mmcv-full>=1.3.14, <1.4.0 |
  14. | 2.16.0 | mmcv-full>=1.3.8, <1.4.0 |
  15. | 2.15.1 | mmcv-full>=1.3.8, <1.4.0 |
  16. | 2.15.0 | mmcv-full>=1.3.8, <1.4.0 |
  17. | 2.14.0 | mmcv-full>=1.3.8, <1.4.0 |
  18. | 2.13.0 | mmcv-full>=1.3.3, <1.4.0 |
  19. | 2.12.0 | mmcv-full>=1.3.3, <1.4.0 |
  20. | 2.11.0 | mmcv-full>=1.2.4, <1.4.0 |
  21. | 2.10.0 | mmcv-full>=1.2.4, <1.4.0 |
  22. | 2.9.0 | mmcv-full>=1.2.4, <1.4.0 |
  23. | 2.8.0 | mmcv-full>=1.2.4, <1.4.0 |
  24. | 2.7.0 | mmcv-full>=1.1.5, <1.4.0 |
  25. | 2.6.0 | mmcv-full>=1.1.5, <1.4.0 |
  26. | 2.5.0 | mmcv-full>=1.1.5, <1.4.0 |
  27. | 2.4.0 | mmcv-full>=1.1.1, <1.4.0 |
  28. | 2.3.0 | mmcv-full==1.0.5 |
  29. | 2.3.0rc0 | mmcv-full>=1.0.2 |
  30. | 2.2.1 | mmcv==0.6.2 |
  31. | 2.2.0 | mmcv==0.6.2 |
  32. | 2.1.0 | mmcv>=0.5.9, <=0.6.1|
  33. | 2.0.0 | mmcv>=0.5.1, <=0.5.8|
  34. **Note:** You need to run `pip uninstall mmcv` first if you have mmcv installed.
  35. If mmcv and mmcv-full are both installed, there will be `ModuleNotFoundError`.
  36. ## Installation
  37. ### Prepare environment
  38. 1. Create a conda virtual environment and activate it.
  39. ```shell
  40. conda create -n openmmlab python=3.7 -y
  41. conda activate openmmlab
  42. ```
  43. 2. Install PyTorch and torchvision following the [official instructions](https://pytorch.org/), e.g.,
  44. ```shell
  45. conda install pytorch torchvision -c pytorch
  46. ```
  47. Note: Make sure that your compilation CUDA version and runtime CUDA version match.
  48. You can check the supported CUDA version for precompiled packages on the [PyTorch website](https://pytorch.org/).
  49. `E.g.1` If you have CUDA 10.1 installed under `/usr/local/cuda` and would like to install
  50. PyTorch 1.5, you need to install the prebuilt PyTorch with CUDA 10.1.
  51. ```shell
  52. conda install pytorch cudatoolkit=10.1 torchvision -c pytorch
  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. ```shell
  57. conda install pytorch=1.3.1 cudatoolkit=9.2 torchvision=0.4.2 -c pytorch
  58. ```
  59. If you build PyTorch from source instead of installing the prebuilt package,
  60. you can use more CUDA versions such as 9.0.
  61. ### Install MMDetection
  62. It is recommended to install MMDetection with [MIM](https://github.com/open-mmlab/mim),
  63. which automatically handle the dependencies of OpenMMLab projects, including mmcv and other python packages.
  64. ```shell
  65. pip install openmim
  66. mim install mmdet
  67. ```
  68. Or you can still install MMDetection manually:
  69. 1. Install mmcv-full.
  70. ```shell
  71. pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
  72. ```
  73. Please replace `{cu_version}` and `{torch_version}` in the url to your desired one. For example, to install the latest `mmcv-full` with `CUDA 11.0` and `PyTorch 1.7.0`, use the following command:
  74. ```shell
  75. pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html
  76. ```
  77. See [here](https://github.com/open-mmlab/mmcv#installation) for different versions of MMCV compatible to different PyTorch and CUDA versions.
  78. Optionally you can compile mmcv from source if you need to develop both mmcv and mmdet. Refer to the [guide](https://github.com/open-mmlab/mmcv#installation) for details.
  79. 2. Install MMDetection.
  80. You can simply install mmdetection with the following command:
  81. ```shell
  82. pip install mmdet
  83. ```
  84. or clone the repository and then install it:
  85. ```shell
  86. git clone https://github.com/open-mmlab/mmdetection.git
  87. cd mmdetection
  88. pip install -r requirements/build.txt
  89. pip install -v -e . # or "python setup.py develop"
  90. ```
  91. 3. Install extra dependencies for Instaboost, Panoptic Segmentation, LVIS dataset, or Albumentations.
  92. ```shell
  93. # for instaboost
  94. pip install instaboostfast
  95. # for panoptic segmentation
  96. pip install git+https://github.com/cocodataset/panopticapi.git
  97. # for LVIS dataset
  98. pip install git+https://github.com/lvis-dataset/lvis-api.git
  99. # for albumentations
  100. pip install albumentations>=0.3.2 --no-binary imgaug,albumentations
  101. ```
  102. **Note:**
  103. a. When specifying `-e` or `develop`, MMDetection is installed on dev mode
  104. , any local modifications made to the code will take effect without reinstallation.
  105. b. If you would like to use `opencv-python-headless` instead of `opencv-python`,
  106. you can install it before installing MMCV.
  107. c. Some dependencies are optional. Simply running `pip install -v -e .` will
  108. 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`.
  109. d. If you would like to use `albumentations`, we suggest using
  110. `pip install albumentations>=0.3.2 --no-binary imgaug,albumentations`. If you simply use
  111. `pip install albumentations>=0.3.2`, it will install `opencv-python-headless` simultaneously (even though you have already installed `opencv-python`). We should not allow `opencv-python` and `opencv-python-headless` installed at the same time, because it might cause unexpected issues. Please refer to [official documentation](https://albumentations.ai/docs/getting_started/installation/#note-on-opencv-dependencies) for more details.
  112. ### Install without GPU support
  113. MMDetection can be built for CPU only environment (where CUDA isn't available).
  114. In CPU mode you can run the demo/webcam_demo.py for example.
  115. However some functionality is gone in this mode:
  116. - Deformable Convolution
  117. - Modulated Deformable Convolution
  118. - ROI pooling
  119. - Deformable ROI pooling
  120. - CARAFE: Content-Aware ReAssembly of FEatures
  121. - SyncBatchNorm
  122. - CrissCrossAttention: Criss-Cross Attention
  123. - MaskedConv2d
  124. - Temporal Interlace Shift
  125. - nms_cuda
  126. - sigmoid_focal_loss_cuda
  127. - bbox_overlaps
  128. If you try to run inference with a model containing above ops, an error will be raised.
  129. The following table lists affected algorithms.
  130. | Operator | Model |
  131. | :-----------------------------------------------------: | :----------------------------------------------------------: |
  132. | Deformable Convolution/Modulated Deformable Convolution | DCN、Guided Anchoring、RepPoints、CentripetalNet、VFNet、CascadeRPN、NAS-FCOS、DetectoRS |
  133. | MaskedConv2d | Guided Anchoring |
  134. | CARAFE | CARAFE |
  135. | SyncBatchNorm | ResNeSt |
  136. **Notice:** MMDetection does not support training with CPU for now.
  137. ### Another option: Docker Image
  138. 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.
  139. ```shell
  140. # build an image with PyTorch 1.6, CUDA 10.1
  141. docker build -t mmdetection docker/
  142. ```
  143. Run it with
  144. ```shell
  145. docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmdetection/data mmdetection
  146. ```
  147. ### A from-scratch setup script
  148. Assuming that you already have CUDA 10.1 installed, here is a full script for setting up MMDetection with conda.
  149. ```shell
  150. conda create -n openmmlab python=3.7 -y
  151. conda activate openmmlab
  152. conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1 -c pytorch -y
  153. # install the latest mmcv
  154. pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.6.0/index.html
  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. ### Developing with multiple MMDetection versions
  162. The train and test scripts already modify the `PYTHONPATH` to ensure the script use the MMDetection in the current directory.
  163. 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
  164. ```shell
  165. PYTHONPATH="$(dirname $0)/..":$PYTHONPATH
  166. ```
  167. ## Verification
  168. To verify whether MMDetection is installed correctly, we can run the following sample code to initialize a detector and inference a demo image.
  169. ```python
  170. from mmdet.apis import init_detector, inference_detector
  171. config_file = 'configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py'
  172. # download the checkpoint from model zoo and put it in `checkpoints/`
  173. # url: https://download.openmmlab.com/mmdetection/v2.0/faster_rcnn/faster_rcnn_r50_fpn_1x_coco/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth
  174. checkpoint_file = 'checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth'
  175. device = 'cuda:0'
  176. # init a detector
  177. model = init_detector(config_file, checkpoint_file, device=device)
  178. # inference the demo image
  179. inference_detector(model, 'demo/demo.jpg')
  180. ```
  181. The above code is supposed to run successfully upon you finish the installation.

No Description

Contributors (3)