getting_started.md 10.5 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
7
8
9
- Python 3.6+
- PyTorch 1.3+
- 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
50
51
52
53
54
55
pip install openmim
mim install mmcv-full
mim install mmdet
mim install mmsegmentation
git clone https://github.com/open-mmlab/mmdetection3d.git
cd mmdetection3d
pip install -e .
xiliu8006's avatar
xiliu8006 committed
56
57
```

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

60
**Step 1.** Install [MMDetection](https://github.com/open-mmlab/mmdetection).
zhangwenwei's avatar
zhangwenwei committed
61

twang's avatar
twang committed
62
```shell
63
pip install mmdet
twang's avatar
twang committed
64
```
zhangwenwei's avatar
zhangwenwei committed
65

twang's avatar
twang committed
66
Optionally, you could also build MMDetection from source in case you want to modify the code:
zhangwenwei's avatar
zhangwenwei committed
67
68

```shell
twang's avatar
twang committed
69
70
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
71
git checkout v2.24.0  # switch to v2.24.0 branch
twang's avatar
twang committed
72
73
pip install -r requirements/build.txt
pip install -v -e .  # or "python setup.py develop"
zhangwenwei's avatar
zhangwenwei committed
74
75
```

76
**Step 2.** Install [MMSegmentation](https://github.com/open-mmlab/mmsegmentation).
77
78

```shell
79
pip install mmsegmentation
80
81
82
83
84
85
86
```

Optionally, you could also build MMSegmentation from source in case you want to modify the code:

```shell
git clone https://github.com/open-mmlab/mmsegmentation.git
cd mmsegmentation
87
git checkout v0.20.0  # switch to v0.20.0 branch
88
89
90
pip install -e .  # or "python setup.py develop"
```

91
**Step 3.** Clone the MMDetection3D repository.
zhangwenwei's avatar
Doc  
zhangwenwei committed
92

twang's avatar
twang committed
93
94
95
96
```shell
git clone https://github.com/open-mmlab/mmdetection3d.git
cd mmdetection3d
```
zhangwenwei's avatar
zhangwenwei committed
97

98
**Step 4.** Install build requirements and then install MMDetection3D.
zhangwenwei's avatar
zhangwenwei committed
99

twang's avatar
twang committed
100
101
102
```shell
pip install -v -e .  # or "python setup.py develop"
```
zhangwenwei's avatar
zhangwenwei committed
103

twang's avatar
twang committed
104
Note:
zhangwenwei's avatar
Doc  
zhangwenwei committed
105

twang's avatar
twang committed
106
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.
107
   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
108

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

111
112
113
114
115
   ```shell
   pip uninstall mmdet3d
   rm -rf ./build
   find . -name "*.so" | xargs rm
   ```
zhangwenwei's avatar
zhangwenwei committed
116

117
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
118

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

twang's avatar
twang committed
122
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
123

VVsssssk's avatar
VVsssssk committed
124
125
126
127
128
129
130
131
132
133
134
135
136
   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).

137
138
   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`:

139
140
141
142
   ```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"
   ```
143

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

146
## Verification
Wenwei Zhang's avatar
Wenwei Zhang committed
147

148
### Verify with point cloud demo
zhangwenwei's avatar
Doc  
zhangwenwei committed
149

150
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
151
152

```shell
wuyuefeng's avatar
Demo  
wuyuefeng committed
153
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
154
155
156
157
158
```

Examples:

```shell
159
python demo/pcd_demo.py demo/data/kitti/kitti_000008.bin configs/second/hv_second_secfpn_6x8_80e_kitti-3d-car.py checkpoints/hv_second_secfpn_6x8_80e_kitti-3d-car_20200620_230238-393f000c.pth
zhangwenwei's avatar
zhangwenwei committed
160
```
161

yinchimaoliang's avatar
yinchimaoliang committed
162
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.
163
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`.
164

yinchimaoliang's avatar
yinchimaoliang committed
165
166
167
168
169
```python
import numpy as np
import pandas as pd
from plyfile import PlyData

170
def convert_ply(input_path, output_path):
yinchimaoliang's avatar
yinchimaoliang committed
171
172
173
174
175
176
177
178
179
180
    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)
```
181

yinchimaoliang's avatar
yinchimaoliang committed
182
Examples:
zhangwenwei's avatar
zhangwenwei committed
183

yinchimaoliang's avatar
yinchimaoliang committed
184
185
186
```python
convert_ply('./test.ply', './test.bin')
```
zhangwenwei's avatar
zhangwenwei committed
187

188
If you have point clouds in other format (`off`, `obj`, etc.), you can use `trimesh` to convert them into `ply`.
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203

```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')
```

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

206
## Customize Installation
zhangwenwei's avatar
zhangwenwei committed
207

208
### CUDA Versions
209

210
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
211

212
213
- 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
214

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
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.
```

### 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.

For example, the following command install mmcv-full built for PyTorch 1.10.x and CUDA 11.3.

```shell
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10/index.html
```

### 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
236

237
238
239
240
```shell
# build an image with PyTorch 1.6, CUDA 10.1
docker build -t mmdetection3d -f docker/Dockerfile .
```
zhangwenwei's avatar
zhangwenwei committed
241

242
Run it with
zhangwenwei's avatar
zhangwenwei committed
243

244
245
```shell
docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmdetection3d/data mmdetection3d
zhangwenwei's avatar
zhangwenwei committed
246
```
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277

### A from-scratch setup script

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

```shell
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab

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

# install mmcv
pip install mmcv-full

# install mmdetection
pip install git+https://github.com/open-mmlab/mmdetection.git

# install mmsegmentation
pip install git+https://github.com/open-mmlab/mmsegmentation.git

# install mmdetection3d
git clone https://github.com/open-mmlab/mmdetection3d.git
cd mmdetection3d
pip install -v -e .
```

## 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.