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
2021-07-20 23:18:47 +08:00
- PyTorch 1.6 or higher
- torchvision 0.7.0
2021-04-03 01:21:33 +08:00
- CUDA 10.1
- NCCL 2
- GCC 5.4.0 or higher
2021-07-20 23:18:47 +08:00
- [MMCV ](https://mmcv.readthedocs.io/en/latest/#installation ) >= 1.3.8
2021-07-21 18:01:55 +08:00
- [MMDetection ](https://mmdetection.readthedocs.io/en/latest/#installation ) >= 2.14.0
2021-04-03 01:21:33 +08:00
2021-10-13 22:56:11 +08:00
We have tested the following versions of OS and software:
2021-04-03 01:21:33 +08:00
- OS: Ubuntu 16.04
- CUDA: 10.1
- GCC(G++): 5.4.0
2021-07-20 23:18:47 +08:00
- MMCV 1.3.8
2021-07-21 18:01:55 +08:00
- MMDetection 2.14.0
2021-07-20 23:18:47 +08:00
- PyTorch 1.6.0
- torchvision 0.7.0
2021-04-03 01:21:33 +08:00
2021-07-20 23:18:47 +08:00
MMOCR depends on PyTorch and mmdetection.
2021-04-03 01:21:33 +08:00
## Step-by-Step Installation Instructions
2021-09-28 11:32:44 +08:00
a. Create a Conda virtual environment and activate it.
2021-04-03 01:21:33 +08:00
```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
2021-07-20 23:18:47 +08:00
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1 -c pytorch
2021-04-03 01:21:33 +08:00
```
2021-09-08 11:40:51 +08:00
:::{note}
2021-09-28 11:32:44 +08:00
Make sure that your compilation CUDA version and runtime CUDA version matches.
2021-04-03 01:21:33 +08:00
You can check the supported CUDA version for precompiled packages on the [PyTorch website ](https://pytorch.org/ ).
2021-09-08 11:40:51 +08:00
:::
2021-04-03 01:21:33 +08:00
2021-09-28 11:32:44 +08:00
c. Install [mmcv ](https://github.com/open-mmlab/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
```
2021-09-28 11:32:44 +08:00
Please replace ``{cu_version}`` and ``{torch_version}`` in the url with your desired one. For example, to install the latest ``mmcv-full`` with CUDA 11 and PyTorch 1.7.0, use the following command:
2021-04-09 00:10:55 +08:00
```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-09-28 11:32:44 +08:00
:::{note}
2022-02-10 09:41:36 +08:00
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.
```
# We can ignore the micro version of PyTorch
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7/index.html
```
:::
:::{note}
2021-07-20 23:18:47 +08:00
Note that mmocr 0.2.1 or later requires mmcv 1.3.8 or later.
2021-04-03 01:21:33 +08:00
2021-09-28 11:32:44 +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.
2021-04-09 00:10:55 +08:00
2021-09-28 11:32:44 +08:00
See official [installation guide ](https://github.com/open-mmlab/mmcv#installation ) for different versions of MMCV compatible to different PyTorch and CUDA versions.
:::
2021-04-09 00:10:55 +08:00
2021-09-28 11:32:44 +08:00
:::{warning}
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` .
:::
2021-04-09 00:10:55 +08:00
2021-09-28 11:32:44 +08:00
d. Install [mmdet ](https://github.com/open-mmlab/mmdetection ), we recommend you to install the latest `mmdet` with pip.
2021-04-17 22:48:15 +08:00
See [here ](https://pypi.org/project/mmdet/ ) for different versions of `mmdet` .
2021-04-09 10:25:40 +08:00
2021-04-09 00:10:55 +08:00
```shell
2021-07-20 23:18:47 +08:00
pip install mmdet
2021-04-09 00:10:55 +08:00
```
2021-09-28 11:32:44 +08:00
Optionally you can choose to install `mmdet` following the official [installation guide ](https://github.com/open-mmlab/mmdetection/blob/master/docs/get_started.md ).
2021-04-03 01:21:33 +08:00
2021-04-09 00:10:55 +08:00
2021-09-28 11:32:44 +08:00
e. Clone the MMOCR repository.
2021-04-03 01:21:33 +08:00
```shell
2021-04-05 15:50:28 +08:00
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-05-20 12:51:22 +08:00
pip install -v -e . # or "python setup.py develop"
2021-04-03 01:21:33 +08:00
export PYTHONPATH=$(pwd):$PYTHONPATH
```
## Full Set-up Script
2021-09-28 11:32:44 +08:00
Here is the full script for setting up MMOCR with Conda.
2021-04-03 01:21:33 +08:00
```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)
2021-07-20 23:18:47 +08:00
conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1 -c pytorch
2021-04-03 01:21:33 +08:00
2021-04-09 10:25:40 +08:00
# install the latest mmcv-full
2021-07-20 23:18:47 +08:00
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.6.0/index.html
2021-04-03 01:21:33 +08:00
# install mmdetection
2021-07-20 23:18:47 +08:00
pip install mmdet
2021-04-03 01:21:33 +08:00
# install mmocr
2021-04-05 15:50:28 +08:00
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
2021-05-20 12:51:22 +08:00
pip install -v -e . # or "python setup.py develop"
2021-04-03 01:21:33 +08:00
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
2021-07-20 23:18:47 +08:00
# build an image with PyTorch 1.6, CUDA 10.1
2021-04-03 01:21:33 +08:00
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
2021-04-09 23:50:33 +08:00
It is recommended to symlink the dataset root to `mmocr/data` . Please refer to [datasets.md ](datasets.md ) to prepare your datasets.
2021-04-03 01:21:33 +08:00
If your folder structure is different, you may need to change the corresponding paths in config files.
The `mmocr` folder is organized as follows:
```
2021-04-09 10:25:40 +08:00
├── configs/
├── demo/
├── docker/
├── docs/
2021-04-04 00:19:55 +08:00
├── LICENSE
2021-04-09 10:25:40 +08:00
├── mmocr/
2021-04-03 01:21:33 +08:00
├── README.md
2021-04-09 10:25:40 +08:00
├── requirements/
2021-04-03 01:21:33 +08:00
├── requirements.txt
2021-04-09 10:25:40 +08:00
├── resources/
2021-04-03 01:21:33 +08:00
├── setup.cfg
├── setup.py
2021-04-09 10:25:40 +08:00
├── tests/
├── tools/
2021-04-03 01:21:33 +08:00
```