Diff of /docs/install.md [000000] .. [6d389a]

Switch to unified view

a b/docs/install.md
1
# Installation
2
3
We provide some tips for MMAction2 installation in this file.
4
5
<!-- TOC -->
6
7
- [Installation](#installation)
8
  - [Requirements](#requirements)
9
  - [Prepare environment](#prepare-environment)
10
  - [Install MMAction2](#install-mmaction2)
11
  - [Install with CPU only](#install-with-cpu-only)
12
  - [Another option: Docker Image](#another-option-docker-image)
13
  - [A from-scratch setup script](#a-from-scratch-setup-script)
14
  - [Developing with multiple MMAction2 versions](#developing-with-multiple-mmaction2-versions)
15
  - [Verification](#verification)
16
17
<!-- TOC -->
18
19
## Requirements
20
21
- Linux (Windows is not officially supported)
22
- Python 3.6+
23
- PyTorch 1.3+
24
- CUDA 9.2+ (If you build PyTorch from source, CUDA 9.0 is also compatible)
25
- GCC 5+
26
- [mmcv](https://github.com/open-mmlab/mmcv) 1.1.1+
27
- Numpy
28
- ffmpeg (4.2 is preferred)
29
- [decord](https://github.com/dmlc/decord) (optional, 0.4.1+): Install CPU version by `pip install decord==0.4.1` and install GPU version from source
30
- [PyAV](https://github.com/mikeboers/PyAV) (optional): `conda install av -c conda-forge -y`
31
- [PyTurboJPEG](https://github.com/lilohuang/PyTurboJPEG) (optional): `pip install PyTurboJPEG`
32
- [denseflow](https://github.com/open-mmlab/denseflow) (optional): See [here](https://github.com/innerlee/setup) for simple install scripts.
33
- [moviepy](https://zulko.github.io/moviepy/) (optional): `pip install moviepy`. See [here](https://zulko.github.io/moviepy/install.html) for official installation.  **Note**(according to [this issue](https://github.com/Zulko/moviepy/issues/693)) that:
34
  1. For Windows users, [ImageMagick](https://www.imagemagick.org/script/index.php) will not be automatically detected by MoviePy,
35
    there is a need to modify `moviepy/config_defaults.py` file by providing the path to the ImageMagick binary called `magick`, like `IMAGEMAGICK_BINARY = "C:\\Program Files\\ImageMagick_VERSION\\magick.exe"`
36
  2. For Linux users, there is a need to modify the `/etc/ImageMagick-6/policy.xml` file by commenting out
37
    `<policy domain="path" rights="none" pattern="@*" />` to `<!-- <policy domain="path" rights="none" pattern="@*" /> -->`, if [ImageMagick](https://www.imagemagick.org/script/index.php) is not detected by `moviepy`.
38
- [Pillow-SIMD](https://docs.fast.ai/performance.html#pillow-simd) (optional): Install it by the following scripts.
39
40
```shell
41
conda uninstall -y --force pillow pil jpeg libtiff libjpeg-turbo
42
pip   uninstall -y         pillow pil jpeg libtiff libjpeg-turbo
43
conda install -yc conda-forge libjpeg-turbo
44
CFLAGS="${CFLAGS} -mavx2" pip install --upgrade --no-cache-dir --force-reinstall --no-binary :all: --compile pillow-simd
45
conda install -y jpeg libtiff
46
```
47
48
:::{note}
49
You need to run `pip uninstall mmcv` first if you have mmcv installed.
50
If mmcv and mmcv-full are both installed, there will be `ModuleNotFoundError`.
51
:::
52
53
## Prepare environment
54
55
a. Create a conda virtual environment and activate it.
56
57
```shell
58
conda create -n open-mmlab python=3.7 -y
59
conda activate open-mmlab
60
```
61
62
b. Install PyTorch and torchvision following the [official instructions](https://pytorch.org/), e.g.,
63
64
```shell
65
conda install pytorch torchvision -c pytorch
66
```
67
68
:::{note}
69
Make sure that your compilation CUDA version and runtime CUDA version match.
70
You can check the supported CUDA version for precompiled packages on the [PyTorch website](https://pytorch.org/).
71
72
`E.g.1` If you have CUDA 10.1 installed under `/usr/local/cuda` and would like to install PyTorch 1.5,
73
you need to install the prebuilt PyTorch with CUDA 10.1.
74
75
```shell
76
conda install pytorch cudatoolkit=10.1 torchvision -c pytorch
77
```
78
79
`E.g.2` If you have CUDA 9.2 installed under `/usr/local/cuda` and would like to install PyTorch 1.3.1.,
80
you need to install the prebuilt PyTorch with CUDA 9.2.
81
82
```shell
83
conda install pytorch=1.3.1 cudatoolkit=9.2 torchvision=0.4.2 -c pytorch
84
```
85
86
If you build PyTorch from source instead of installing the prebuilt package, you can use more CUDA versions such as 9.0.
87
:::
88
89
## Install MMAction2
90
91
We recommend you to install MMAction2 with [MIM](https://github.com/open-mmlab/mim).
92
93
```shell
94
pip install git+https://github.com/open-mmlab/mim.git
95
mim install mmaction2 -f https://github.com/open-mmlab/mmaction2.git
96
```
97
98
MIM can automatically install OpenMMLab projects and their requirements.
99
100
Or, you can install MMAction2 manually:
101
102
a. Install mmcv, we recommend you to install the pre-build mmcv as below.
103
104
```shell
105
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
106
```
107
108
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`` and ``PyTorch 1.7.0``, use the following command:
109
110
```shell
111
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html
112
```
113
114
See [here](https://github.com/open-mmlab/mmcv#installation) for different versions of MMCV compatible to different PyTorch and CUDA versions.
115
116
Optionally you can choose to compile mmcv from source by the following command
117
118
```shell
119
git clone https://github.com/open-mmlab/mmcv.git
120
cd mmcv
121
MMCV_WITH_OPS=1 pip install -e .  # package mmcv-full, which contains cuda ops, will be installed after this step
122
# OR pip install -e .  # package mmcv, which contains no cuda ops, will be installed after this step
123
cd ..
124
```
125
126
Or directly run
127
128
```shell
129
pip install mmcv-full
130
# alternative: pip install mmcv
131
```
132
133
**Important:** You need to run `pip uninstall mmcv` first if you have mmcv installed. If mmcv and mmcv-full are both installed, there will be `ModuleNotFoundError`.
134
135
b. Clone the MMAction2 repository.
136
137
```shell
138
git clone https://github.com/open-mmlab/mmaction2.git
139
cd mmaction2
140
```
141
142
c. Install build requirements and then install MMAction2.
143
144
```shell
145
pip install -r requirements/build.txt
146
pip install -v -e .  # or "python setup.py develop"
147
```
148
149
If you build MMAction2 on macOS, replace the last command with
150
151
```shell
152
CC=clang CXX=clang++ CFLAGS='-stdlib=libc++' pip install -e .
153
```
154
155
d. Install mmdetection for spatial temporal detection tasks.
156
157
This part is **optional** if you're not going to do spatial temporal detection.
158
159
See [here](https://github.com/open-mmlab/mmdetection#installation) to install mmdetection.
160
161
:::{note}
162
163
1. The git commit id will be written to the version number with step b, e.g. 0.6.0+2e7045c. The version will also be saved in trained models.
164
   It is recommended that you run step b each time you pull some updates from github. If C++/CUDA codes are modified, then this step is compulsory.
165
166
2. Following the above instructions, MMAction2 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).
167
168
3. If you would like to use `opencv-python-headless` instead of `opencv-python`,
169
   you can install it before installing MMCV.
170
171
4. If you would like to use `PyAV`, you can install it with `conda install av -c conda-forge -y`.
172
173
5. Some dependencies are optional. Running `python setup.py develop` will only install the minimum runtime requirements.
174
   To use optional dependencies like `decord`, either install them with `pip install -r requirements/optional.txt`
175
   or specify desired extras when calling `pip` (e.g. `pip install -v -e .[optional]`,
176
   valid keys for the `[optional]` field are `all`, `tests`, `build`, and `optional`) like `pip install -v -e .[tests,build]`.
177
178
:::
179
180
## Install with CPU only
181
182
The code can be built for CPU only environment (where CUDA isn't available).
183
184
In CPU mode you can run the demo/demo.py for example.
185
186
## Another option: Docker Image
187
188
We provide a [Dockerfile](/docker/Dockerfile) to build an image.
189
190
```shell
191
# build an image with PyTorch 1.6.0, CUDA 10.1, CUDNN 7.
192
docker build -f ./docker/Dockerfile --rm -t mmaction2 .
193
```
194
195
**Important:** Make sure you've installed the [nvidia-container-toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker).
196
197
Run it with command:
198
199
```shell
200
docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmaction2/data mmaction2
201
```
202
203
## A from-scratch setup script
204
205
Here is a full script for setting up MMAction2 with conda and link the dataset path (supposing that your Kinetics-400 dataset path is $KINETICS400_ROOT).
206
207
```shell
208
conda create -n open-mmlab python=3.7 -y
209
conda activate open-mmlab
210
211
# install latest pytorch prebuilt with the default prebuilt CUDA version (usually the latest)
212
conda install -c pytorch pytorch torchvision -y
213
214
# install the latest mmcv or mmcv-full, here we take mmcv as example
215
pip install mmcv
216
217
# install mmaction2
218
git clone https://github.com/open-mmlab/mmaction2.git
219
cd mmaction2
220
pip install -r requirements/build.txt
221
python setup.py develop
222
223
mkdir data
224
ln -s $KINETICS400_ROOT data
225
```
226
227
## Developing with multiple MMAction2 versions
228
229
The train and test scripts already modify the `PYTHONPATH` to ensure the script use the MMAction2 in the current directory.
230
231
To use the default MMAction2 installed in the environment rather than that you are working with, you can remove the following line in those scripts.
232
233
```shell
234
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH
235
```
236
237
## Verification
238
239
To verify whether MMAction2 and the required environment are installed correctly,
240
we can run sample python codes to initialize a recognizer and inference a demo video:
241
242
```python
243
import torch
244
from mmaction.apis import init_recognizer, inference_recognizer
245
246
config_file = 'configs/recognition/tsn/tsn_r50_video_inference_1x1x3_100e_kinetics400_rgb.py'
247
device = 'cuda:0' # or 'cpu'
248
device = torch.device(device)
249
250
model = init_recognizer(config_file, device=device)
251
# inference the demo video
252
inference_recognizer(model, 'demo/demo.mp4')
253
```