INSTALL.md 5.58 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
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
12
- PyTorch 2.1.0, 2.1.1, 2.1.2, 2.2.0, 2.2.1, 2.2.2, 2.3.0, 2.3.1, 2.4.0 or 2.4.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
- gcc & g++ ≥ 4.9
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
15
- [ioPath](https://github.com/facebookresearch/iopath)
16
- If CUDA is to be used, use a version which is supported by the corresponding pytorch version and at least version 9.2.
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
17
- If CUDA older than 11.7 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
18

19
The runtime dependencies can be installed by running:
facebook-github-bot's avatar
facebook-github-bot committed
20
```
21
conda create -n pytorch3d python=3.9
facebook-github-bot's avatar
facebook-github-bot committed
22
conda activate pytorch3d
23
conda install pytorch=1.13.0 torchvision pytorch-cuda=11.6 -c pytorch -c nvidia
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
24
conda install -c iopath iopath
25
26
```

27
For the CUB build time dependency, which you only need if you have CUDA older than 11.7, if you are using conda, you can continue with
28
29
30
31
32
33
34
```
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
35
curl -LO https://github.com/NVIDIA/cub/archive/1.10.0.tar.gz
36
37
tar xzf 1.10.0.tar.gz
export CUB_HOME=$PWD/cub-1.10.0
facebook-github-bot's avatar
facebook-github-bot committed
38
39
40
41
```

### Tests/Linting and Demos

Christoph Lassner's avatar
Christoph Lassner committed
42
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
43
44
- scikit-image
- black
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
45
- usort
facebook-github-bot's avatar
facebook-github-bot committed
46
47
48
49
50
- flake8
- matplotlib
- tdqm
- jupyter
- imageio
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
51
- fvcore
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
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
62
conda install -c fvcore -c conda-forge fvcore
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
63
pip install black usort flake8 flake8-bugbear flake8-comprehensions
facebook-github-bot's avatar
facebook-github-bot committed
64
65
```

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

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

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

Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
76
77
78
79
80
Or, to install a nightly (non-official, alpha) build:
```
# Anaconda Cloud
conda install pytorch3d -c pytorch3d-nightly
```
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
81

82
### 2. Install wheels for Linux
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
83
We have prebuilt wheels with CUDA for Linux for PyTorch 1.11.0, for each of the supported CUDA versions,
84
for Python 3.8 and 3.9. This is for ease of use on Google Colab.
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
85
These are installed in a special way.
Christian Kauten's avatar
Christian Kauten committed
86
For example, to install for Python 3.8, PyTorch 1.11.0 and CUDA 11.3
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
87
```
Christian Kauten's avatar
Christian Kauten committed
88
pip install --no-index --no-cache-dir pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/py38_cu113_pyt1110/download.html
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
89
90
91
92
93
94
```

In general, from inside IPython, or in Google Colab or a jupyter notebook, you can install with
```
import sys
import torch
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
95
pyt_version_str=torch.__version__.split("+")[0].replace(".", "")
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
96
97
98
version_str="".join([
    f"py3{sys.version_info.minor}_cu",
    torch.version.cuda.replace(".",""),
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
99
    f"_pyt{pyt_version_str}"
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
100
])
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
101
!pip install iopath
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
102
!pip install --no-index --no-cache-dir pytorch3d -f https://dl.fbaipublicfiles.com/pytorch3d/packaging/wheels/{version_str}/download.html
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
103
```
104
105

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

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

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

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

### 2. Install from a local clone
facebook-github-bot's avatar
facebook-github-bot committed
127
128
129
130
```
git clone https://github.com/facebookresearch/pytorch3d.git
cd pytorch3d && pip install -e .
```
Christoph Lassner's avatar
Christoph Lassner committed
131
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
132
133
134

**Install from local clone on macOS:**
```
135
MACOSX_DEPLOYMENT_TARGET=10.14 CC=clang CXX=clang++ pip install -e .
facebook-github-bot's avatar
facebook-github-bot committed
136
```
137
138
139

**Install from local clone on Windows:**

140
Depending on the version of PyTorch, changes to some PyTorch headers may be needed before compilation. These are often discussed in issues in this repository.
141

142
After any necessary patching, you can go to "x64 Native Tools Command Prompt for VS 2019" to compile and install
143
144
145
146
```
cd pytorch3d
python3 setup.py install
```
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
147
148

After installing, you can run **unit tests**
149
```
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
150
python3 -m unittest discover -v -s tests -t .
Jeremy Reizenstein's avatar
Jeremy Reizenstein committed
151
```
Nikhila Ravi's avatar
Nikhila Ravi committed
152
153
154
155
156
157

# 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).