mmpretrain/docs/en/install.md

144 lines
4.6 KiB
Markdown
Raw Normal View History

# Installation
2020-07-08 10:46:10 +08:00
## Requirements
2020-07-08 10:46:10 +08:00
- Python 3.6+
- PyTorch 1.5+
2021-04-01 10:39:18 +08:00
- [MMCV](https://github.com/open-mmlab/mmcv)
The compatible MMClassification and MMCV versions are as below. Please install the correct version of MMCV to avoid installation issues.
2021-10-29 14:04:03 +08:00
| MMClassification version | MMCV version |
|:------------------------:|:---------------------:|
| master | mmcv>=1.3.16, <=1.5.0 |
| 0.18.0 | mmcv>=1.3.16, <=1.5.0 |
2021-10-29 14:04:03 +08:00
| 0.17.0 | mmcv>=1.3.8, <=1.5.0 |
| 0.16.0 | mmcv>=1.3.8, <=1.5.0 |
| 0.15.0 | mmcv>=1.3.8, <=1.5.0 |
| 0.15.0 | mmcv>=1.3.8, <=1.5.0 |
| 0.14.0 | mmcv>=1.3.8, <=1.5.0 |
| 0.13.0 | mmcv>=1.3.8, <=1.5.0 |
| 0.12.0 | mmcv>=1.3.1, <=1.5.0 |
| 0.11.1 | mmcv>=1.3.1, <=1.5.0 |
| 0.11.0 | mmcv>=1.3.0 |
| 0.10.0 | mmcv>=1.3.0 |
| 0.9.0 | mmcv>=1.1.4 |
| 0.8.0 | mmcv>=1.1.4 |
| 0.7.0 | mmcv>=1.1.4 |
| 0.6.0 | mmcv>=1.1.4 |
2021-07-05 10:19:57 +08:00
```{note}
Since the `master` branch is under frequent development, the `mmcv`
2021-07-05 10:19:57 +08:00
version dependency may be inaccurate. If you encounter problems when using
the `master` branch, please try to update `mmcv` to the latest version.
```
2020-07-08 10:46:10 +08:00
## Install MMClassification
2020-07-08 10:46:10 +08:00
a. Create a conda virtual environment and activate it.
```shell
2021-10-29 14:04:03 +08:00
conda create -n open-mmlab python=3.8 -y
2020-07-08 10:46:10 +08:00
conda activate open-mmlab
```
b. Install PyTorch and torchvision following the [official instructions](https://pytorch.org/), e.g.,
```shell
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](https://pytorch.org/).
```
2020-07-08 10:46:10 +08:00
`E.g.1` If you have CUDA 10.1 installed under `/usr/local/cuda` and would like to install
2021-10-29 14:04:03 +08:00
PyTorch 1.5.1, you need to install the prebuilt PyTorch with CUDA 10.1.
2020-07-08 10:46:10 +08:00
```shell
2021-10-29 14:04:03 +08:00
conda install pytorch==1.5.1 torchvision==0.6.1 cudatoolkit=10.1 -c pytorch
2020-07-08 10:46:10 +08:00
```
2021-10-29 14:04:03 +08:00
`E.g.2` If you have CUDA 11.3 installed under `/usr/local/cuda` and would like to install
PyTorch 1.10.0., you need to install the prebuilt PyTorch with CUDA 11.3.
2020-07-08 10:46:10 +08:00
```shell
2021-10-29 14:04:03 +08:00
conda install pytorch==1.10.0 torchvision==0.11.1 cudatoolkit=11.3 -c pytorch
2020-07-08 10:46:10 +08:00
```
If you build PyTorch from source instead of installing the prebuilt package,
2020-07-08 10:46:10 +08:00
you can use more CUDA versions such as 9.0.
c. Install MMClassification repository.
### Release version
We recommend you to install MMClassification with [MIM](https://github.com/open-mmlab/mim).
```shell
pip install git+https://github.com/open-mmlab/mim.git
mim install mmcls
```
MIM can automatically install OpenMMLab projects and their requirements,
and it can also help us to train, parameter search and pretrain model download.
Or, you can install MMClassification with pip:
```shell
pip install mmcls
```
### Develop version
First, clone the MMClassification repository.
2020-07-08 10:46:10 +08:00
```shell
git clone https://github.com/open-mmlab/mmclassification.git
cd mmclassification
```
And then, install build requirements and install MMClassification.
2020-07-08 10:46:10 +08:00
```shell
pip install -e . # or "python setup.py develop"
```
```{note}
Following above instructions, MMClassification 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).
```
2020-07-08 10:46:10 +08:00
### Another option: Docker Image
We provide a [Dockerfile](https://github.com/open-mmlab/mmclassification/blob/master/docker/Dockerfile) to build an image.
```shell
# build an image with PyTorch 1.8.1, CUDA 10.2, CUDNN 7 and MMCV-full latest version released.
docker build -f ./docker/Dockerfile --rm -t mmcls:latest .
```
```{important}
Make sure you've installed the [nvidia-container-toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker).
```
Run a container built from mmcls image with command:
```shell
docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/workspace/mmclassification/data mmcls:latest /bin/bash
```
## Using multiple MMClassification versions
2020-07-08 10:46:10 +08:00
The train and test scripts already modify the `PYTHONPATH` to ensure the script use the MMClassification in the current directory.
To use the default MMClassification installed in the environment rather than that you are working with, you can remove the following line in those scripts
```shell
PYTHONPATH="$(dirname $0)/..":$PYTHONPATH
```