mmocr/docs/install.md

182 lines
5.2 KiB
Markdown
Raw Normal View History

2021-04-03 01:21:33 +08:00
# Installation
2021-04-04 11:56:14 +08:00
2021-04-03 01:21:33 +08:00
## Prerequisites
- Linux (Windows is not officially supported)
- Python 3.7
- PyTorch 1.5 or higher
2021-04-03 01:21:33 +08:00
- torchvision 0.6.0
- CUDA 10.1
- NCCL 2
- GCC 5.4.0 or higher
- [mmcv](https://github.com/open-mmlab/mmcv) 1.2.6
We have tested the following versions of OS and softwares:
- OS: Ubuntu 16.04
- CUDA: 10.1
- GCC(G++): 5.4.0
- mmcv 1.2.6
- PyTorch 1.5
- torchvision 0.6.0
MMOCR depends on Pytorch and mmdetection v2.9.0.
## Step-by-Step Installation Instructions
a. Create a conda virtual environment and activate it.
```shell
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab
```
b. Install PyTorch and torchvision following the [official instructions](https://pytorch.org/), e.g.,
```shell
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=10.1 -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/).
2021-04-09 00:10:55 +08:00
`E.g.` If you have CUDA 10.1 installed under `/usr/local/cuda` and would like to install
2021-04-03 01:21:33 +08:00
PyTorch 1.5, you need to install the prebuilt PyTorch with CUDA 10.1.
```python
conda install pytorch cudatoolkit=10.1 torchvision -c pytorch
```
2021-04-09 00:10:55 +08:00
c. Install mmcv, we recommend you to install the pre-build mmcv as below.
2021-04-03 01:21:33 +08:00
2021-04-09 00:10:55 +08:00
```shell
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
```
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:
```shell
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html
2021-04-03 01:21:33 +08:00
```
2021-04-09 00:10:55 +08:00
If it compiles during installation, then please check that the cuda version and pytorch version **exactly"" matches the version in the mmcv-full installation command. For example, pytorch 1.7.0 and 1.7.1 are treated differently.
See [here](https://github.com/open-mmlab/mmcv#installation) for different versions of MMCV compatible to different PyTorch and CUDA versions.
2021-04-03 01:21:33 +08:00
2021-04-09 00:10:55 +08:00
Optionally you can choose to compile mmcv from source by the following command
2021-04-03 01:21:33 +08:00
```shell
git clone https://github.com/open-mmlab/mmcv.git
cd mmcv
2021-04-09 00:10:55 +08:00
2021-04-03 01:21:33 +08:00
git checkout -b v1.2.6 v1.2.6
2021-04-09 00:10:55 +08:00
MMCV_WITH_OPS=1 pip install -e . # package mmcv-full, which contains cuda ops, will be installed after this step
# OR pip install -e . # package mmcv, which contains no cuda ops, will be installed after this step
cd ..
2021-04-03 01:21:33 +08:00
```
2021-04-09 00:10:55 +08:00
Or directly run
```shell
pip install mmcv-full
# alternative: pip install mmcv
```
**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`.
d. Install [mmdet](https://github.com/open-mmlab/mmdetection.git), we recommend you to install mmdet with pip.
See [here](https://pypi.org/project/mmdet/2.9.0/) for different versions of mmdet.
```shell
pip install mmdet==2.9.0
```
Optionally you can choose to install mmdetection from [source](https://github.com/open-mmlab/mmdetection.git) by the following command
2021-04-03 01:21:33 +08:00
```shell
git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
2021-04-09 00:10:55 +08:00
2021-04-03 01:21:33 +08:00
git checkout -b v2.9.0 v2.9.0
pip install -r requirements.txt
export PYTHONPATH=$(pwd):$PYTHONPATH
```
Note that we have tested mmdetection v2.9.0 only. Other versions might be incompatible.
2021-04-09 00:10:55 +08:00
e. Clone the mmocr repository.
2021-04-03 01:21:33 +08:00
```shell
git clone https://github.com/open-mmlab/mmocr.git
2021-04-03 01:21:33 +08:00
cd mmocr
```
f. Install build requirements and then install MMOCR.
```shell
pip install -r requirements.txt
2021-04-09 00:10:55 +08:00
pip install -v -e . # or "python setup.py build_ext --inplace"
2021-04-03 01:21:33 +08:00
export PYTHONPATH=$(pwd):$PYTHONPATH
```
## Full Set-up Script
Here is the full script for setting up mmocr with conda.
```shell
conda create -n open-mmlab python=3.7 -y
conda activate open-mmlab
# install latest pytorch prebuilt with the default prebuilt CUDA version (usually the latest)
conda install pytorch==1.5.0 torchvision==0.6.0 cudatoolkit=10.1 -c pytorch
2021-04-09 00:10:55 +08:00
# install the latest mmcv-full or mmcv, here we take mmcv-full as example
pip install mmcv-full
2021-04-03 01:21:33 +08:00
# install mmdetection
2021-04-09 00:10:55 +08:00
pip install mmdet==2.9.0
2021-04-03 01:21:33 +08:00
# install mmocr
git clone https://github.com/open-mmlab/mmocr.git
2021-04-09 00:10:55 +08:00
cd mmocr
2021-04-03 01:21:33 +08:00
pip install -r requirements.txt
pip install -v -e . # or "python setup.py build_ext --inplace"
export PYTHONPATH=$(pwd):$PYTHONPATH
```
## Another option: Docker Image
We provide a [Dockerfile](https://github.com/open-mmlab/mmocr/blob/master/docker/Dockerfile) to build an image.
```shell
# build an image with PyTorch 1.5, CUDA 10.1
docker build -t mmocr docker/
```
Run it with
```shell
docker run --gpus all --shm-size=8g -it -v {DATA_DIR}:/mmocr/data mmocr
```
## Prepare Datasets
It is recommended to symlink the dataset root to `mmocr/data`. Please refer to [datasets.md](datasets.md) to prepare your datasets.
If your folder structure is different, you may need to change the corresponding paths in config files.
The `mmocr` folder is organized as follows:
```
├── configs
├── demo
2021-04-08 10:23:03 +08:00
├── docker
2021-04-03 01:21:33 +08:00
├── docs
├── LICENSE
2021-04-03 01:21:33 +08:00
├── mmocr
├── README.md
├── requirements
├── requirements.txt
├── resources
├── setup.cfg
├── setup.py
├── tests
2021-04-08 10:23:03 +08:00
├── tools
2021-04-03 01:21:33 +08:00
```