getting_started.md 10.6 KB
Newer Older
twang's avatar
twang committed
1
# Prerequisites
2

3
4
In this section we demonstrate how to prepare an environment with PyTorch.
MMDection3D works on Linux, Windows (experimental support) and macOS and requires the following packages:
zhangwenwei's avatar
zhangwenwei committed
5

twang's avatar
twang committed
6
- Python 3.6+
7
- PyTorch 1.6+
twang's avatar
twang committed
8
9
- CUDA 9.2+ (If you build PyTorch from source, CUDA 9.0 is also compatible)
- GCC 5+
xiliu8006's avatar
xiliu8006 committed
10
11
- [MMCV](https://mmcv.readthedocs.io/en/latest/#installation)

12
13
```{note}
If you are experienced with PyTorch and have already installed it, just skip this part and jump to the [next section](#installation). Otherwise, you can follow these steps for the preparation.
Wenwei Zhang's avatar
Wenwei Zhang committed
14
15
```

16
**Step 0.** Download and install Miniconda from the [official website](https://docs.conda.io/en/latest/miniconda.html).
Wenwei Zhang's avatar
Wenwei Zhang committed
17

18
**Step 1.** Create a conda environment and activate it.
Wenwei Zhang's avatar
Wenwei Zhang committed
19

20
```shell
21
22
conda create --name openmmlab python=3.8 -y
conda activate openmmlab
Wenwei Zhang's avatar
Wenwei Zhang committed
23
24
```

25
**Step 2.** Install PyTorch following [official instructions](https://pytorch.org/get-started/locally/), e.g.
zhangwenwei's avatar
zhangwenwei committed
26

27
On GPU platforms:
zhangwenwei's avatar
zhangwenwei committed
28

Ziyi Wu's avatar
Ziyi Wu committed
29
```shell
30
conda install pytorch torchvision -c pytorch
xiliu8006's avatar
xiliu8006 committed
31
32
```

33
On CPU platforms:
xiliu8006's avatar
xiliu8006 committed
34

twang's avatar
twang committed
35
```shell
36
conda install pytorch torchvision cpuonly -c pytorch
twang's avatar
twang committed
37
```
zhangwenwei's avatar
zhangwenwei committed
38

39
# Installation
40

41
We recommend that users follow our best practices to install MMDetection3D. However, the whole process is highly customizable. See [Customize Installation](#customize-installation) section for more information.
42

43
## Best Practices
44

45
46
Assuming that you already have CUDA 11.0 installed, here is a full script for quick installation of MMDetection3D with conda.
Otherwise, you should refer to the step-by-step installation instructions in the next section.
zhangwenwei's avatar
zhangwenwei committed
47

twang's avatar
twang committed
48
```shell
49
pip install openmim
50
mim install mmengine
51
52
mim install 'mmcv>=2.0.0rc0'
mim install 'mmdet>=3.0.0rc0'
53
git clone https://github.com/open-mmlab/mmdetection3d.git -b dev-1.x
54
55
cd mmdetection3d
pip install -e .
xiliu8006's avatar
xiliu8006 committed
56
57
```

58
**Step 0.** Install [MMEngine](https://github.com/open-mmlab/mmengine) and [MMCV](https://github.com/open-mmlab/mmcv) using [MIM](https://github.com/open-mmlab/mim).
zhangwenwei's avatar
zhangwenwei committed
59
60

```shell
61
62
pip install -U openmim
mim install mmengine
63
mim install 'mmcv>=2.0.0rc0'
zhangwenwei's avatar
zhangwenwei committed
64
65
```

66
**Step 1.** Install [MMDetection](https://github.com/open-mmlab/mmdetection).
67
68

```shell
69
mim install 'mmdet>=3.0.0rc0'
70
71
```

72
Optionally, you could also build MMDetection from source in case you want to modify the code:
73
74

```shell
75
76
77
78
79
80
81
git clone https://github.com/open-mmlab/mmdetection.git -b dev-3.x
# "-b dev-3.x" means checkout to the `dev-3.x` branch.
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.
82
83
```

84
**Step 2.** Clone the MMDetection3D repository.
zhangwenwei's avatar
Doc  
zhangwenwei committed
85

twang's avatar
twang committed
86
```shell
87
88
git clone https://github.com/open-mmlab/mmdetection3d.git -b dev-1.x
# "-b dev-1.x" means checkout to the `dev-1.x` branch.
twang's avatar
twang committed
89
90
cd mmdetection3d
```
zhangwenwei's avatar
zhangwenwei committed
91

92
**Step 3.** Install build requirements and then install MMDetection3D.
zhangwenwei's avatar
zhangwenwei committed
93

twang's avatar
twang committed
94
95
96
```shell
pip install -v -e .  # or "python setup.py develop"
```
zhangwenwei's avatar
zhangwenwei committed
97

twang's avatar
twang committed
98
Note:
zhangwenwei's avatar
Doc  
zhangwenwei committed
99

twang's avatar
twang committed
100
1. The git commit id will be written to the version number with step d, e.g. 0.6.0+2e7045c. The version will also be saved in trained models.
101
   It is recommended that you run step d each time you pull some updates from github. If C++/CUDA codes are modified, then this step is compulsory.
zhangwenwei's avatar
Doc  
zhangwenwei committed
102

103
   > Important: Be sure to remove the `./build` folder if you reinstall mmdet with a different CUDA/PyTorch version.
zhangwenwei's avatar
zhangwenwei committed
104

105
106
107
108
109
   ```shell
   pip uninstall mmdet3d
   rm -rf ./build
   find . -name "*.so" | xargs rm
   ```
zhangwenwei's avatar
zhangwenwei committed
110

111
2. Following the above instructions, MMDetection3D is installed on `dev` mode, any local modifications made to the code will take effect without the need to reinstall it (unless you submit some commits and want to update the version number).
zhangwenwei's avatar
zhangwenwei committed
112

twang's avatar
twang committed
113
3. If you would like to use `opencv-python-headless` instead of `opencv-python`,
114
   you can install it before installing MMCV.
zhangwenwei's avatar
zhangwenwei committed
115

twang's avatar
twang committed
116
4. Some dependencies are optional. Simply running `pip install -v -e .` will 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`.
zhangwenwei's avatar
zhangwenwei committed
117

VVsssssk's avatar
VVsssssk committed
118
119
120
121
122
123
124
125
126
127
128
129
130
   We have supported spconv2.0. If the user has installed spconv2.0, the code will use spconv2.0 first, which will take up less GPU memory than using the default mmcv spconv. Users can use the following commands to install spconv2.0:

   ```bash
   pip install cumm-cuxxx
   pip install spconv-cuxxx
   ```

   Where xxx is the CUDA version in the environment.

   For example, using CUDA 10.2, the command will be `pip install cumm-cu102 && pip install spconv-cu102`.

   Supported CUDA versions include 10.2, 11.1, 11.3, and 11.4. Users can also install it by building from the source. For more details please refer to [spconv v2.x](https://github.com/traveller59/spconv).

131
132
   We also support Minkowski Engine as a sparse convolution backend. If necessary please follow original [installation guide](https://github.com/NVIDIA/MinkowskiEngine#installation) or use `pip`:

133
134
135
136
   ```shell
   conda install openblas-devel -c anaconda
   pip install -U git+https://github.com/NVIDIA/MinkowskiEngine -v --no-deps --install-option="--blas_include_dirs=/opt/conda/include" --install-option="--blas=openblas"
   ```
137

twang's avatar
twang committed
138
5. The code can not be built for CPU only environment (where CUDA isn't available) for now.
zhangwenwei's avatar
zhangwenwei committed
139

140
## Verification
Wenwei Zhang's avatar
Wenwei Zhang committed
141

142
### Verify with point cloud demo
zhangwenwei's avatar
Doc  
zhangwenwei committed
143

144
We provide several demo scripts to test a single sample. Pre-trained models can be downloaded from [model zoo](model_zoo.md). To test a single-modality 3D detection on point cloud scenes:
zhangwenwei's avatar
Doc  
zhangwenwei committed
145
146

```shell
wuyuefeng's avatar
Demo  
wuyuefeng committed
147
python demo/pcd_demo.py ${PCD_FILE} ${CONFIG_FILE} ${CHECKPOINT_FILE} [--device ${GPU_ID}] [--score-thr ${SCORE_THR}] [--out-dir ${OUT_DIR}]
zhangwenwei's avatar
Doc  
zhangwenwei committed
148
149
150
151
152
```

Examples:

```shell
153
python demo/pcd_demo.py demo/data/kitti/000008.bin configs/second/second_hv-secfpn_8xb6-80e_kitti-3d-car.py checkpoints/second_hv-secfpn_8xb6-80e_kitti-3d-car_20200620_230238-393f000c.pth
zhangwenwei's avatar
zhangwenwei committed
154
```
155

yinchimaoliang's avatar
yinchimaoliang committed
156
If you want to input a `ply` file, you can use the following function and convert it to `bin` format. Then you can use the converted `bin` file to generate demo.
157
Note that you need to install `pandas` and `plyfile` before using this script. This function can also be used for data preprocessing for training `ply data`.
158

yinchimaoliang's avatar
yinchimaoliang committed
159
160
161
162
163
```python
import numpy as np
import pandas as pd
from plyfile import PlyData

164
def convert_ply(input_path, output_path):
yinchimaoliang's avatar
yinchimaoliang committed
165
166
167
168
169
170
171
172
173
174
    plydata = PlyData.read(input_path)  # read file
    data = plydata.elements[0].data  # read data
    data_pd = pd.DataFrame(data)  # convert to DataFrame
    data_np = np.zeros(data_pd.shape, dtype=np.float)  # initialize array to store data
    property_names = data[0].dtype.names  # read names of properties
    for i, name in enumerate(
            property_names):  # read data by property
        data_np[:, i] = data_pd[name]
    data_np.astype(np.float32).tofile(output_path)
```
175

yinchimaoliang's avatar
yinchimaoliang committed
176
Examples:
zhangwenwei's avatar
zhangwenwei committed
177

yinchimaoliang's avatar
yinchimaoliang committed
178
179
180
```python
convert_ply('./test.ply', './test.bin')
```
zhangwenwei's avatar
zhangwenwei committed
181

182
If you have point clouds in other format (`off`, `obj`, etc.), you can use `trimesh` to convert them into `ply`.
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

```python
import trimesh

def to_ply(input_path, output_path, original_type):
    mesh = trimesh.load(input_path, file_type=original_type)  # read file
    mesh.export(output_path, file_type='ply')  # convert to ply
```

Examples:

```python
to_ply('./test.obj', './test.ply', 'obj')
```

198
More demos about single/multi-modality and indoor/outdoor 3D detection can be found in [demo](demo.md).
199

200
## Customize Installation
zhangwenwei's avatar
zhangwenwei committed
201

202
### CUDA Versions
203

204
When installing PyTorch, you need to specify the version of CUDA. If you are not clear on which to choose, follow our recommendations:
Ziyi Wu's avatar
Ziyi Wu committed
205

206
207
- For Ampere-based NVIDIA GPUs, such as GeForce 30 series and NVIDIA A100, CUDA 11 is a must.
- For older NVIDIA GPUs, CUDA 11 is backward compatible, but CUDA 10.2 offers better compatibility and is more lightweight.
zhangwenwei's avatar
zhangwenwei committed
208

209
210
211
212
213
214
Please make sure the GPU driver satisfies the minimum version requirements. See [this table](https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html#cuda-major-component-versions__table-cuda-toolkit-driver-versions) for more information.

```{note}
Installing CUDA runtime libraries is enough if you follow our best practices, because no CUDA code will be compiled locally. However if you hope to compile MMCV from source or develop other CUDA operators, you need to install the complete CUDA toolkit from NVIDIA's [website](https://developer.nvidia.com/cuda-downloads), and its version should match the CUDA version of PyTorch. i.e., the specified version of cudatoolkit in `conda install` command.
```

215
216
217
218
219
220
221
222
223
224
### Install MMEngine without MIM

To install MMEngine with pip instead of MIM, please follow [MMEngine installation guides](https://mmcv.readthedocs.io/en/latest/get_started/installation.html).

For example, you can install MMEngine by the following command.

```shell
pip install mmengine
```

225
226
227
228
229
230
### Install MMCV without MIM

MMCV contains C++ and CUDA extensions, thus depending on PyTorch in a complex way. MIM solves such dependencies automatically and makes the installation easier. However, it is not a must.

To install MMCV with pip instead of MIM, please follow [MMCV installation guides](https://mmcv.readthedocs.io/en/latest/get_started/installation.html). This requires manually specifying a find-url based on PyTorch version and its CUDA version.

231
For example, the following command install mmcv built for PyTorch 1.10.x and CUDA 11.3.
232
233

```shell
234
pip install mmcv -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10/index.html
235
236
237
238
239
```

### Using MMDetection3D with Docker

We provide a [Dockerfile](https://github.com/open-mmlab/mmdetection3d/blob/master/docker/Dockerfile) to build an image.
zhangwenwei's avatar
zhangwenwei committed
240

241
242
243
244
```shell
# build an image with PyTorch 1.6, CUDA 10.1
docker build -t mmdetection3d -f docker/Dockerfile .
```
zhangwenwei's avatar
zhangwenwei committed
245

246
Run it with
zhangwenwei's avatar
zhangwenwei committed
247

248
249
```shell
docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmdetection3d/data mmdetection3d
zhangwenwei's avatar
zhangwenwei committed
250
```
251
252
253
254
255
256

### A from-scratch setup script

Here is a full script for setting up MMdetection3D with conda.

```shell
257
conda create -n open-mmlab python=3.8 -y
258
259
260
261
262
conda activate open-mmlab

# install latest PyTorch prebuilt with the default prebuilt CUDA version (usually the latest)
conda install -c pytorch pytorch torchvision -y

263
264
265
# install mmengine and mmcv
pip install openmim
mim install mmengine
266
mim install 'mmcv>=2.0.0rc0'
267
268

# install mmdetection
269
mim install 'mmdet>=3.0.0rc0'
270
271

# install mmdetection3d
272
git clone https://github.com/open-mmlab/mmdetection3d.git -b dev-1.x
273
cd mmdetection3d
274
pip install -e .
275
276
277
278
279
280
```

## Trouble shooting

If you have some issues during the installation, please first view the [FAQ](faq.md) page.
You may [open an issue](https://github.com/open-mmlab/mmdetection3d/issues/new/choose) on GitHub if no solution is found.