- Linux (Windows is not officially supported)
- Python 3.6+
- PyTorch 1.3+
- CUDA 9.2+ (If you build PyTorch from source, CUDA 9.0 is also compatible)
- GCC 5+
- mmcv 0.5.7+
- Numpy
- ffmpeg (4.2 is preferred)
- decord (optional): Install CPU version by
pip install decord
and install GPU version from source - PyAV (optional):
conda install av -c conda-forge -y
- PyTurboJPEG (optional):
pip install PyTurboJPEG
- denseflow (optional): See here for simple install scripts.
- moviepy (optional):
pip install moviepy
. See here for official installation. Note(according to this issue) that:- For Windows users, ImageMagick will not be automatically detected by MoviePy,
there is a need to modify
moviepy/config_defaults.py
file by providing the path to the ImageMagick binary calledmagick
, likeIMAGEMAGICK_BINARY = "C:\\Program Files\\ImageMagick_VERSION\\magick.exe"
- For Linux users, there is a need to modify the
/etc/ImageMagick-6/policy.xml
file by commenting out<policy domain="path" rights="none" pattern="@*" />
to<!-- <policy domain="path" rights="none" pattern="@*" /> -->
, if ImageMagick is not detected bymoviepy
.
- For Windows users, ImageMagick will not be automatically detected by MoviePy,
there is a need to modify
- Pillow-SIMD (optional): Install it by the following scripts.
conda uninstall -y --force pillow pil jpeg libtiff libjpeg-turbo
pip uninstall -y pillow pil jpeg libtiff libjpeg-turbo
conda install -yc conda-forge libjpeg-turbo
CFLAGS="${CFLAGS} -mavx2" pip install --upgrade --no-cache-dir --force-reinstall --no-binary :all: --compile pillow-simd
conda install -y jpeg libtiff
a. Create a conda virtual environment and activate it.
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab
b. Install PyTorch and torchvision following the official instructions, e.g.,
conda install pytorch torchvision -c pytorch
Note: Make sure that your compilation CUDA version and runtime CUDA version match. You can check the supported CUDA version for precompiled packages on the PyTorch website.
E.g.1
If you have CUDA 10.1 installed under /usr/local/cuda
and would like to install PyTorch 1.5,
you need to install the prebuilt PyTorch with CUDA 10.1.
conda install pytorch cudatoolkit=10.1 torchvision -c pytorch
E.g.2
If you have CUDA 9.2 installed under /usr/local/cuda
and would like to install PyTorch 1.3.1.,
you need to install the prebuilt PyTorch with CUDA 9.2.
conda install pytorch=1.3.1 cudatoolkit=9.2 torchvision=0.4.2 -c pytorch
If you build PyTorch from source instead of installing the prebuilt package, you can use more CUDA versions such as 9.0.
c. Clone the mmaction2 repository
git clone https://github.com/open-mmlab/mmaction2.git
cd mmaction2
d. Install build requirements and then install mmaction2
pip install -r requirements/build.txt
pip install -v -e . # or "python setup.py develop"
If you build mmaction2 on macOS, replace the last command with
CC=clang CXX=clang++ CFLAGS='-stdlib=libc++' pip install -e .
Note:
-
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. 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.
-
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). -
If you would like to use
opencv-python-headless
instead ofopencv-python
, you can install it before installing MMCV. -
If you would like to use
PyAV
, you can install it withconda install av -c conda-forge -y
. -
Some dependencies are optional. Running
python setup.py develop
will only install the minimum runtime requirements. To use optional dependencies likedecord
, either install them withpip install -r requirements/optional.txt
or specify desired extras when callingpip
(e.g.pip install -v -e .[optional]
, valid keys for the[optional]
field areall
,tests
,build
, andoptional
) likepip install -v -e .[tests,build]
.
The code can be built for CPU only environment (where CUDA isn't available).
In CPU mode you can run the demo/demo.py for example.
We provide a Dockerfile to build an image.
# build an image with PyTorch 1.5, CUDA 10.1
docker build -t mmaction docker/
Run it with
docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmaction/data mmaction
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).
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab
conda install -c pytorch pytorch torchvision -y
git clone https://github.com/open-mmlab/mmaction.git
cd mmaction
pip install -r requirements/build.txt
python setup.py develop
mkdir data
ln -s $KINETICS400_ROOT data
The train and test scripts already modify the PYTHONPATH
to ensure the script use the MMAction2 in the current directory.
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.
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH