13 KiB
Installation
There are two versions of MMCV:
- mmcv-full: comprehensive, with full features and various CPU and CUDA ops out of box. It takes longer time to build.
- mmcv: lite, without CPU and CUDA ops but all other features, similar to mmcv<1.0.0. It is useful when you do not need those CUDA ops.
Do not install both versions in the same environment, otherwise you may encounter errors like `ModuleNotFound`. You need to uninstall one before installing the other. `Installing the full version is highly recommended if CUDA is avaliable`.
Install mmcv-full
- To compile ONNX Runtime custom operators, please refer to [How to build custom operators for ONNX Runtime](../deployment/onnxruntime_op.md#how-to-build-custom-operators-for-onnx-runtime)
- To compile TensorRT customization, please refer to [How to build TensorRT plugins in MMCV](../deployment/tensorrt_plugin.md#how-to-build-tensorrt-plugins-in-mmcv)
Before installing mmcv-full, make sure that PyTorch has been successfully installed following the PyTorch official installation guide. This can be verified using the following command
python -c 'import torch;print(torch.__version__)'
If version information is output, then PyTorch is installed.
Install with mim (recommended)
mim is the package management tool for the OpenMMLab projects, which makes it easy to install mmcv-full
pip install -U openmim
mim install mmcv-full
If you find that the above installation command does not use a pre-built package ending with .whl
but a source package ending with .tar.gz
, you may not have a pre-build package corresponding to the PyTorch or CUDA or mmcv-full version, in which case you can build mmcv-full from source.
Installation log using pre-built packages
Looking in links: https://download.openmmlab.com/mmcv/dist/cu102/torch1.8.0/index.html
Collecting mmcv-full
Downloading https://download.openmmlab.com/mmcv/dist/cu102/torch1.8.0/mmcv_full-1.6.1-cp38-cp38-manylinux1_x86_64.whl
Installation log using source packages
Looking in links: https://download.openmmlab.com/mmcv/dist/cu102/torch1.8.0/index.html
Collecting mmcv-full==1.6.0
Downloading mmcv-full-1.6.0.tar.gz
To install a specific version of mmcv-full, for example, mmcv-full version 1.7.0, you can use the following command
mim install mmcv-full==1.7.0
:::{note}
If you would like to use opencv-python-headless
instead of opencv-python
,
e.g., in a minimum container environment or servers without GUI,
you can first install it before installing MMCV to skip the installation of opencv-python
.
Alternatively, if it takes too long to install a dependency library, you can specify the pypi source
mim install mmcv-full -i https://pypi.tuna.tsinghua.edu.cn/simple
:::
You can run check_installation.py to check the installation of mmcv-full after running the installation commands.
Install with pip
Use the following command to check the version of CUDA and PyTorch
python -c 'import torch;print(torch.__version__);print(torch.version.cuda)'
Select the appropriate installation command depending on the type of system, CUDA version, PyTorch version, and MMCV version
<html>If you do not find a corresponding version in the dropdown box above, you probably do not have a pre-built package corresponding to the PyTorch or CUDA or mmcv-full version, at which point you can build mmcv-full from source.
:::{note} mmcv-full is only compiled on PyTorch 1.x.0 because the compatibility usually holds between 1.x.0 and 1.x.1. If your PyTorch version is 1.x.1, you can install mmcv-full compiled with PyTorch 1.x.0 and it usually works well. For example, if your PyTorch version is 1.8.1, you can feel free to choose 1.8.x. :::
:::{note}
If you would like to use opencv-python-headless
instead of opencv-python
,
e.g., in a minimum container environment or servers without GUI,
you can first install it before installing MMCV to skip the installation of opencv-python
.
Alternatively, if it takes too long to install a dependency library, you can specify the pypi source
mim install mmcv-full -i https://pypi.tuna.tsinghua.edu.cn/simple
:::
You can run check_installation.py to check the installation of mmcv-full after running the installation commands.
Using mmcv-full with Docker
Build with local repository
git clone https://github.com/open-mmlab/mmcv.git && cd mmcv
docker build -t mmcv -f docker/release/Dockerfile .
Or build with remote repository
docker build -t mmcv https://github.com/open-mmlab/mmcv.git#master:docker/release
The Dockerfile installs latest released version of mmcv-full by default, but you can specify mmcv versions to install expected versions.
docker image build -t mmcv -f docker/release/Dockerfile --build-arg MMCV=1.5.0 .
If you also want to use other versions of PyTorch and CUDA, you can also pass them when building docker images.
An example to build an image with PyTorch 1.11 and CUDA 11.3.
docker build -t mmcv -f docker/release/Dockerfile \
--build-arg PYTORCH=1.9.0 \
--build-arg CUDA=11.1 \
--build-arg CUDNN=8 \
--build-arg MMCV=1.5.0 .
More available versions of PyTorch and CUDA can be found at dockerhub/pytorch.
Install mmcv
If you need to use PyTorch-related modules, make sure PyTorch has been successfully installed in your environment by referring to the PyTorch official installation guide.
pip install mmcv