installation.md 10.8 KB
Newer Older
Zaida Zhou's avatar
Zaida Zhou committed
1
2
## 安装 MMCV

3
4
MMCV 有两个版本:

Zaida Zhou's avatar
Zaida Zhou committed
5
6
- **mmcv**: 完整版,包含所有的特性以及丰富的开箱即用的 CUDA 算子。注意完整版本可能需要更长时间来编译。
- **mmcv-lite**: 精简版,不包含 CUDA 算子但包含其余所有特性和功能,类似 MMCV 1.0 之前的版本。如果你不需要使用 CUDA 算子的话,精简版可以作为一个考虑选项。
7

zhouzaida's avatar
zhouzaida committed
8
```{warning}
Zaida Zhou's avatar
Zaida Zhou committed
9
请不要在同一个环境中安装两个版本,否则可能会遇到类似 `ModuleNotFound` 的错误。在安装一个版本之前,需要先卸载另一个。`如果CUDA可用,强烈推荐安装 mmcv`。
zhouzaida's avatar
zhouzaida committed
10
```
11
12
13

a. 安装完整版

Zaida Zhou's avatar
Zaida Zhou committed
14
在安装 mmcv 之前,请确保 PyTorch 已经成功安装在环境中,可以参考 PyTorch 官方[文档](https://pytorch.org/)
15

Zaida Zhou's avatar
Zaida Zhou committed
16
我们提供了 **Linux 和 Windows 平台** PyTorch 和 CUDA 版本组合的 mmcv 预编译包,可以大大简化用户安装编译过程。强烈推荐通过预编译包来安装。另外,安装完成后可以运行 [check_installation.py](https://github.com/open-mmlab/mmcv/.dev_scripts/check_installation.py) 脚本检查 mmcv 是否安装成功。
17
18
19

i. 安装最新版本

Zaida Zhou's avatar
Zaida Zhou committed
20
如下是安装最新版 `mmcv` 的命令
21
22

```shell
Zaida Zhou's avatar
Zaida Zhou committed
23
pip install 'mmcv>=2.0.0rc1' -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
24
25
```

Zaida Zhou's avatar
Zaida Zhou committed
26
请将链接中的 `{cu_version}``{torch_version}` 根据自身需求替换成实际的版本号,例如想安装和 `CUDA 11.1``PyTorch 1.9.0` 兼容的最新版 `mmcv`,使用如下替换过的命令
27
28

```shell
Zaida Zhou's avatar
Zaida Zhou committed
29
pip install 'mmcv>=2.0.0rc1' -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html
30
31
```

zhouzaida's avatar
zhouzaida committed
32
```{note}
Zaida Zhou's avatar
Zaida Zhou committed
33
34
35
PyTorch 在 1.x.0 和 1.x.1 之间通常是兼容的,故 mmcv 只提供 1.x.0 的编译包。如果你
的 PyTorch 版本是 1.x.1,你可以放心地安装在 1.x.0 版本编译的 mmcv。例如,如果你的
PyTorch 版本是 1.8.1、CUDA 版本是 11.1,你可以使用以下命令安装 mmcv。
Zaida Zhou's avatar
Zaida Zhou committed
36

Zaida Zhou's avatar
Zaida Zhou committed
37
`pip install mmcv -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/index.html`
Zaida Zhou's avatar
Zaida Zhou committed
38
39
```

40
如果想知道更多 CUDA 和 PyTorch 版本的命令,可以参考下面的表格,将链接中的 `=={mmcv_version}` 删去即可。
41
42
43

ii. 安装特定的版本

Zaida Zhou's avatar
Zaida Zhou committed
44
如下是安装特定版本 `mmcv` 的命令
45
46

```shell
Zaida Zhou's avatar
Zaida Zhou committed
47
pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/{cu_version}/{torch_version}/index.html
48
49
```

Zaida Zhou's avatar
Zaida Zhou committed
50
51
首先请参考版本发布信息找到想要安装的版本号,将 `{mmcv_version}` 替换成该版本号,例如 `2.0.0rc1`
然后将链接中的 `{cu_version}``{torch_version}` 根据自身需求替换成实际的版本号,例如想安装和 `CUDA 11.1``PyTorch 1.9.0` 兼容的 `mmcv` 2.0.0rc1 版本,使用如下替换过的命令
52
53

```shell
Zaida Zhou's avatar
Zaida Zhou committed
54
pip install mmcv==2.0.0rc1 -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html
55
56
57
58
59
60
61
62
```

对于更多的 PyTorch 和 CUDA 版本组合,请参考下表:

<table class="docutils">
  <tbody>
    <tr>
      <th width="80"> CUDA </th>
63
64
65
66
67
68
69
70
71
72
      <th valign="bottom" align="left" width="120">torch 1.11</th>
      <th valign="bottom" align="left" width="120">torch 1.10</th>
      <th valign="bottom" align="left" width="120">torch 1.9</th>
      <th valign="bottom" align="left" width="120">torch 1.8</th>
      <th valign="bottom" align="left" width="120">torch 1.7</th>
      <th valign="bottom" align="left" width="120">torch 1.6</th>
      <th valign="bottom" align="left" width="120">torch 1.5</th>
    </tr>
    <tr>
      <td align="left">11.5</td>
Zaida Zhou's avatar
Zaida Zhou committed
73
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu115/torch1.11.0/index.html</code></pre> </details> </td>
74
75
76
77
78
79
      <td align="left"> </td>
      <td align="left"></td>
      <td align="left"></code></pre> </details> </td>
      <td align="left"> </td>
      <td align="left"> </td>
      <td align="left"> </td>
80
    </tr>
81
82
    <tr>
      <td align="left">11.3</td>
Zaida Zhou's avatar
Zaida Zhou committed
83
84
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.11.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu113/torch1.10.0/index.html</code></pre> </details> </td>
85
86
87
88
89
90
      <td align="left"></td>
      <td align="left"></code></pre> </details> </td>
      <td align="left"> </td>
      <td align="left"> </td>
      <td align="left"> </td>
    </tr>
91
92
    <tr>
      <td align="left">11.1</td>
93
      <td align="left"> </td>
Zaida Zhou's avatar
Zaida Zhou committed
94
95
96
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.10.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.9.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu111/torch1.8.0/index.html</code></pre> </details> </td>
97
98
99
100
101
102
103
104
      <td align="left"> </td>
      <td align="left"> </td>
      <td align="left"> </td>
    </tr>
    <tr>
      <td align="left">11.0</td>
      <td align="left"> </td>
      <td align="left"> </td>
105
      <td align="left"> </td>
106
      <td align="left"> </td>
Zaida Zhou's avatar
Zaida Zhou committed
107
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu110/torch1.7.0/index.html</code></pre> </details> </td>
108
109
110
111
112
      <td align="left"> </td>
      <td align="left"> </td>
    </tr>
    <tr>
      <td align="left">10.2</td>
Zaida Zhou's avatar
Zaida Zhou committed
113
114
115
116
117
118
119
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.11.0/index.html</code></pre> </details></td>
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.10.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.9.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.8.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.7.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.6.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code>pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.5.0/index.html</code></pre> </details> </td>
120
121
122
123
    </tr>
    <tr>
      <td align="left">10.1</td>
      <td align="left"> </td>
124
      <td align="left"> </td>
125
      <td align="left"> </td>
Zaida Zhou's avatar
Zaida Zhou committed
126
127
128
129
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.8.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.7.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.6.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.5.0/index.html</code></pre> </details> </td>
130
131
132
133
134
    </tr>
    <tr>
      <td align="left">9.2</td>
      <td align="left"> </td>
      <td align="left"> </td>
135
      <td align="left"> </td>
136
      <td align="left"> </td>
Zaida Zhou's avatar
Zaida Zhou committed
137
138
139
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu92/torch1.7.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu92/torch1.6.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cu92/torch1.5.0/index.html</code></pre> </details> </td>
140
141
142
    </tr>
    <tr>
      <td align="left">cpu</td>
Zaida Zhou's avatar
Zaida Zhou committed
143
144
145
146
147
148
149
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.11.0/index.html</code></pre> </details></td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.10.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.9.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.8.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.7.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.6.0/index.html</code></pre> </details> </td>
      <td align="left"><details><summary> 安装 </summary><pre><code> pip install mmcv=={mmcv_version} -f https://download.openmmlab.com/mmcv/dist/cpu/torch1.5.0/index.html</code></pre> </details> </td>
150
151
152
153
    </tr>
  </tbody>
</table>

zhouzaida's avatar
zhouzaida committed
154
```{note}
Zaida Zhou's avatar
Zaida Zhou committed
155
mmcv 没有提供 Windows 平台 `cu102-torch1.8.0` 和 `cu92-torch*` 的预编译包。
156
157
```

158
159
160
除了使用预编译包之外,另一种方式是在本地进行编译,直接运行下述命令

```python
Zaida Zhou's avatar
Zaida Zhou committed
161
pip install 'mmcv>=2.0.0rc1'
162
163
164
165
166
167
168
```

但注意本地编译可能会耗时 10 分钟以上。

b. 安装精简版

```python
Zaida Zhou's avatar
Zaida Zhou committed
169
pip install mmcv-lite
170
171
172
```

如果想从源码编译 MMCV,请参考[该文档](https://mmcv.readthedocs.io/zh_CN/latest/get_started/build.html)