getting_started.md 11 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
# We recommend to install python=3.8 since the waymo-open-dataset-tf-2-6-0 requires python>=3.7
# If you want to install python<3.7, make sure to install waymo-open-dataset-tf-2-x-0 (x<=4)
23
24
conda create --name openmmlab python=3.8 -y
conda activate openmmlab
Wenwei Zhang's avatar
Wenwei Zhang committed
25
26
```

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

29
On GPU platforms:
zhangwenwei's avatar
zhangwenwei committed
30

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

35
On CPU platforms:
xiliu8006's avatar
xiliu8006 committed
36

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

41
# Installation
42

43
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.
44

45
## Best Practices
46

47
48
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
49

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

60
**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
61
62

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

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

```shell
71
mim install 'mmdet>=3.0.0rc0'
72
73
```

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

```shell
77
78
79
80
81
82
83
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.
84
85
```

86
**Step 2.** Clone the MMDetection3D repository.
zhangwenwei's avatar
Doc  
zhangwenwei committed
87

twang's avatar
twang committed
88
```shell
89
90
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
91
92
cd mmdetection3d
```
zhangwenwei's avatar
zhangwenwei committed
93

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

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

twang's avatar
twang committed
100
Note:
zhangwenwei's avatar
Doc  
zhangwenwei committed
101

twang's avatar
twang committed
102
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.
103
   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
104

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

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

113
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
114

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

twang's avatar
twang committed
118
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
119

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

133
134
   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`:

135
136
137
138
   ```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"
   ```
139

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

142
## Verification
Wenwei Zhang's avatar
Wenwei Zhang committed
143

144
### Verify with point cloud demo
zhangwenwei's avatar
Doc  
zhangwenwei committed
145

146
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
147
148

```shell
wuyuefeng's avatar
Demo  
wuyuefeng committed
149
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
150
151
152
153
154
```

Examples:

```shell
155
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
156
```
157

yinchimaoliang's avatar
yinchimaoliang committed
158
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.
159
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`.
160

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

166
def convert_ply(input_path, output_path):
yinchimaoliang's avatar
yinchimaoliang committed
167
168
169
170
171
172
173
174
175
176
    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)
```
177

yinchimaoliang's avatar
yinchimaoliang committed
178
Examples:
zhangwenwei's avatar
zhangwenwei committed
179

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

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

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

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

202
## Customize Installation
zhangwenwei's avatar
zhangwenwei committed
203

204
### CUDA Versions
205

206
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
207

208
209
- 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
210

211
212
213
214
215
216
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.
```

217
218
219
220
221
222
223
224
225
226
### 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
```

227
228
229
230
231
232
### 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.

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

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

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

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

248
Run it with
zhangwenwei's avatar
zhangwenwei committed
249

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

### A from-scratch setup script

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

```shell
259
260
# We recommend to install python=3.8 since the waymo-open-dataset-tf-2-6-0 requires python>=3.7
# If you want to install python<3.7, make sure to install waymo-open-dataset-tf-2-x-0 (x<=4)
261
conda create -n open-mmlab python=3.8 -y
262
263
264
265
266
conda activate open-mmlab

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

267
268
269
# install mmengine and mmcv
pip install openmim
mim install mmengine
270
mim install 'mmcv>=2.0.0rc0'
271
272

# install mmdetection
273
mim install 'mmdet>=3.0.0rc0'
274
275

# install mmdetection3d
276
git clone https://github.com/open-mmlab/mmdetection3d.git -b dev-1.x
277
cd mmdetection3d
278
pip install -e .
279
280
281
282
283
284
```

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