INSTALL.md 6.02 KB
Newer Older
facebook-github-bot's avatar
facebook-github-bot committed
1
2
3
4
5
6
7
# Installation


## Requirements

### Core library

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
8
The core library is written in PyTorch. Several components have underlying implementation in CUDA for improved performance. A subset of these components have CPU implementations in C++/PyTorch. It is advised to use PyTorch3D with GPU support in order to use all the features.
facebook-github-bot's avatar
facebook-github-bot committed
9

10
- Linux or macOS or Windows
11
- Python 3.6, 3.7 or 3.8
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
12
- PyTorch 1.4, 1.5.0, 1.5.1, 1.6.0, 1.7.0, or 1.7.1.
13
- torchvision that matches the PyTorch installation. You can install them together as explained at pytorch.org to make sure of this.
facebook-github-bot's avatar
facebook-github-bot committed
14
15
- gcc & g++ ≥ 4.9
- [fvcore](https://github.com/facebookresearch/fvcore)
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
16
- [ioPath](https://github.com/facebookresearch/iopath)
17
18
- If CUDA is to be used, use a version which is supported by the corresponding pytorch version and at least version 9.2.
- If CUDA is to be used and you are building from source, the CUB library must be available. We recommend version 1.10.0.
facebook-github-bot's avatar
facebook-github-bot committed
19

20
The runtime dependencies can be installed by running:
facebook-github-bot's avatar
facebook-github-bot committed
21
```
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
22
conda create -n pytorch3d python=3.8
facebook-github-bot's avatar
facebook-github-bot committed
23
conda activate pytorch3d
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
24
conda install -c pytorch pytorch=1.7.1 torchvision cudatoolkit=10.2
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
25
conda install -c fvcore -c iopath -c conda-forge fvcore iopath
26
27
28
29
30
31
32
33
34
35
```

For the CUB build time dependency, if you are using conda, you can continue with
```
conda install -c bottler nvidiacub
```
Otherwise download the CUB library from https://github.com/NVIDIA/cub/releases and unpack it to a folder of your choice.
Define the environment variable CUB_HOME before building and point it to the directory that contains `CMakeLists.txt` for CUB.
For example on Linux/Mac,
```
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
36
curl -LO https://github.com/NVIDIA/cub/archive/1.10.0.tar.gz
37
38
tar xzf 1.10.0.tar.gz
export CUB_HOME=$PWD/cub-1.10.0
facebook-github-bot's avatar
facebook-github-bot committed
39
40
41
42
```

### Tests/Linting and Demos

Christoph Lassner's avatar
Christoph Lassner committed
43
For developing on top of PyTorch3D or contributing, you will need to run the linter and tests. If you want to run any of the notebook tutorials as `docs/tutorials` or the examples in `docs/examples` you will also need matplotlib and OpenCV.
facebook-github-bot's avatar
facebook-github-bot committed
44
45
46
47
48
49
50
51
- scikit-image
- black
- isort
- flake8
- matplotlib
- tdqm
- jupyter
- imageio
52
- plotly
Christoph Lassner's avatar
Christoph Lassner committed
53
- opencv-python
facebook-github-bot's avatar
facebook-github-bot committed
54
55
56

These can be installed by running:
```
Christoph Lassner's avatar
Christoph Lassner committed
57
# Demos and examples
facebook-github-bot's avatar
facebook-github-bot committed
58
conda install jupyter
Christoph Lassner's avatar
Christoph Lassner committed
59
pip install scikit-image matplotlib imageio plotly opencv-python
facebook-github-bot's avatar
facebook-github-bot committed
60
61

# Tests/Linting
62
pip install black 'isort<5' flake8 flake8-bugbear flake8-comprehensions
facebook-github-bot's avatar
facebook-github-bot committed
63
64
```

65
## Installing prebuilt binaries for PyTorch3D
facebook-github-bot's avatar
facebook-github-bot committed
66
67
After installing the above dependencies, run one of the following commands:

68
### 1. Install with CUDA support from Anaconda Cloud, on Linux only
facebook-github-bot's avatar
facebook-github-bot committed
69
70
71

```
# Anaconda Cloud
Yun Chen's avatar
Yun Chen committed
72
conda install pytorch3d -c pytorch3d
facebook-github-bot's avatar
facebook-github-bot committed
73
74
```

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
75
76
77
78
79
Or, to install a nightly (non-official, alpha) build:
```
# Anaconda Cloud
conda install pytorch3d -c pytorch3d-nightly
```
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
80
81
### 2. Install from PyPI, on Mac only.
This works with pytorch 1.7.1 only. The build is CPU only.
82
83
84
```
pip install pytorch3d
```
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104

### 3. Install wheels for Linux
We have prebuilt wheels with CUDA for Linux for PyTorch 1.7.0 and 1.7.1, for each of the CUDA versions that they support.
These are installed in a special way.
For example, to install for Python 3.6, PyTorch 1.7.0 and CUDA 10.1
```
pip install pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/py36_cu101_pyt170/download.html
```

In general, from inside IPython, or in Google Colab or a jupyter notebook, you can install with
```
import sys
import torch
version_str="".join([
    f"py3{sys.version_info.minor}_cu",
    torch.version.cuda.replace(".",""),
    f"_pyt{torch.__version__[0:5:2]}"
])
!pip install pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/{version_str}/download.html
```
105
106

## Building / installing from source.
107
CUDA support will be included if CUDA is available in pytorch or if the environment variable
108
`FORCE_CUDA` is set to `1`.
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
109

110
### 1. Install from GitHub
facebook-github-bot's avatar
facebook-github-bot committed
111
```
112
pip install "git+https://github.com/facebookresearch/pytorch3d.git"
facebook-github-bot's avatar
facebook-github-bot committed
113
```
114
115
To install using the code of the released version instead of from the main branch, use the following instead.
```
116
pip install "git+https://github.com/facebookresearch/pytorch3d.git@stable"
117
```
facebook-github-bot's avatar
facebook-github-bot committed
118

Christoph Lassner's avatar
Christoph Lassner committed
119
120
For CUDA builds with versions earlier than CUDA 11, set `CUB_HOME` before building as described above.

121
**Install from Github on macOS:**
122
Some environment variables should be provided, like this.
123
```
124
MACOSX_DEPLOYMENT_TARGET=10.14 CC=clang CXX=clang++ pip install "git+https://github.com/facebookresearch/pytorch3d.git"
125
126
127
```

### 2. Install from a local clone
facebook-github-bot's avatar
facebook-github-bot committed
128
129
130
131
```
git clone https://github.com/facebookresearch/pytorch3d.git
cd pytorch3d && pip install -e .
```
Christoph Lassner's avatar
Christoph Lassner committed
132
To rebuild after installing from a local clone run, `rm -rf build/ **/*.so` then `pip install -e .`. You often need to rebuild pytorch3d after reinstalling PyTorch. For CUDA builds with versions earlier than CUDA 11, set `CUB_HOME` before building as described above.
facebook-github-bot's avatar
facebook-github-bot committed
133
134
135

**Install from local clone on macOS:**
```
136
MACOSX_DEPLOYMENT_TARGET=10.14 CC=clang CXX=clang++ pip install -e .
facebook-github-bot's avatar
facebook-github-bot committed
137
```
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174

**Install from local clone on Windows:**

If you are using pre-compiled pytorch 1.4 and torchvision 0.5, you should make the following changes to the pytorch source code to successfully compile with Visual Studio 2019 (MSVC 19.16.27034) and CUDA 10.1.

Change python/Lib/site-packages/torch/include/csrc/jit/script/module.h

L466, 476, 493, 506, 536
```
-static constexpr *
+static const *
```
Change python/Lib/site-packages/torch/include/csrc/jit/argument_spec.h

L190
```
-static constexpr size_t DEPTH_LIMIT = 128;
+static const size_t DEPTH_LIMIT = 128;
```

Change python/Lib/site-packages/torch/include/pybind11/cast.h

L1449
```
-explicit operator type&() { return *(this->value); }
+explicit operator type& () { return *((type*)(this->value)); }
```

After patching, you can go to "x64 Native Tools Command Prompt for VS 2019" to compile and install
```
cd pytorch3d
python3 setup.py install
```
After installing, verify whether all unit tests have passed
```
cd tests
python3 -m unittest discover -p *.py
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
175
```
Nikhila Ravi's avatar
Nikhila Ravi committed
176
177
178
179
180
181

# FAQ

### Can I use Docker?

We don't provide a docker file but see [#113](https://github.com/facebookresearch/pytorch3d/issues/113) for a docker file shared by a user (NOTE: this has not been tested by the PyTorch3D team).