getting_started.md 10.5 KB
Newer Older
twang's avatar
twang committed
1
# Prerequisites
2
3
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
4

twang's avatar
twang committed
5
6
7
8
- 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
9
10
- [MMCV](https://mmcv.readthedocs.io/en/latest/#installation)

11
12
```{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
13
14
```

15
**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
16

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

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

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

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

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

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

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

38
# Installation
39

40
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.
41

42
43
44
## Best Practices
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
45

twang's avatar
twang committed
46
```shell
47
48
49
50
51
52
53
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
54
55
```

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

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


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

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

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

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

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

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
86
git checkout v0.20.0  # switch to v0.20.0 branch
87
88
89
pip install -e .  # or "python setup.py develop"
```

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Wenwei Zhang's avatar
Wenwei Zhang 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
209
### CUDA Versions
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
210

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

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

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

243
Run it with
zhangwenwei's avatar
zhangwenwei committed
244

245
246
```shell
docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmdetection3d/data mmdetection3d
zhangwenwei's avatar
zhangwenwei committed
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
278

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