|
| 1 | +# torchvision |
| 2 | + |
| 3 | +[](https://pepy.tech/project/torchvision) |
| 4 | +[](https://pytorch.org/vision/stable/index.html) |
| 5 | + |
| 6 | +The torchvision package consists of popular datasets, model architectures, and common image transformations for computer |
| 7 | +vision. |
| 8 | + |
| 9 | +## Installation |
| 10 | + |
| 11 | +We recommend Anaconda as Python package management system. Please refer to [pytorch.org](https://pytorch.org/) for the |
| 12 | +detail of PyTorch (`torch`) installation. The following is the corresponding `torchvision` versions and supported Python |
| 13 | +versions. |
| 14 | + |
| 15 | +| `torch` | `torchvision` | Python | |
| 16 | +| ------------------ | ------------------ | ------------------- | |
| 17 | +| `main` / `nightly` | `main` / `nightly` | `>=3.8`, `<=3.11` | |
| 18 | +| `2.0` | `0.15` | `>=3.8`, `<=3.11` | |
| 19 | +| `1.13` | `0.14` | `>=3.7.2`, `<=3.10` | |
| 20 | +| `1.12` | `0.13` | `>=3.7`, `<=3.10` | |
| 21 | + |
| 22 | +<details> |
| 23 | + <summary>older versions</summary> |
| 24 | + |
| 25 | +| `torch` | `torchvision` | Python | |
| 26 | +|---------|-------------------|---------------------------| |
| 27 | +| `1.11` | `0.12` | `>=3.7`, `<=3.10` | |
| 28 | +| `1.10` | `0.11` | `>=3.6`, `<=3.9` | |
| 29 | +| `1.9` | `0.10` | `>=3.6`, `<=3.9` | |
| 30 | +| `1.8` | `0.9` | `>=3.6`, `<=3.9` | |
| 31 | +| `1.7` | `0.8` | `>=3.6`, `<=3.9` | |
| 32 | +| `1.6` | `0.7` | `>=3.6`, `<=3.8` | |
| 33 | +| `1.5` | `0.6` | `>=3.5`, `<=3.8` | |
| 34 | +| `1.4` | `0.5` | `==2.7`, `>=3.5`, `<=3.8` | |
| 35 | +| `1.3` | `0.4.2` / `0.4.3` | `==2.7`, `>=3.5`, `<=3.7` | |
| 36 | +| `1.2` | `0.4.1` | `==2.7`, `>=3.5`, `<=3.7` | |
| 37 | +| `1.1` | `0.3` | `==2.7`, `>=3.5`, `<=3.7` | |
| 38 | +| `<=1.0` | `0.2` | `==2.7`, `>=3.5`, `<=3.7` | |
| 39 | + |
| 40 | +</details> |
| 41 | + |
| 42 | +Anaconda: |
| 43 | + |
| 44 | +``` |
| 45 | +conda install torchvision -c pytorch |
| 46 | +``` |
| 47 | + |
| 48 | +pip: |
| 49 | + |
| 50 | +``` |
| 51 | +pip install torchvision |
| 52 | +``` |
| 53 | + |
| 54 | +From source: |
| 55 | + |
| 56 | +``` |
| 57 | +python setup.py install |
| 58 | +# or, for OSX |
| 59 | +# MACOSX_DEPLOYMENT_TARGET=10.9 CC=clang CXX=clang++ python setup.py install |
| 60 | +``` |
| 61 | + |
| 62 | +We don't officially support building from source using `pip`, but _if_ you do, you'll need to use the |
| 63 | +`--no-build-isolation` flag. In case building TorchVision from source fails, install the nightly version of PyTorch |
| 64 | +following the linked guide on the |
| 65 | +[contributing page](https://github.com/pytorch/vision/blob/main/CONTRIBUTING.md#development-installation) and retry the |
| 66 | +install. |
| 67 | + |
| 68 | +By default, GPU support is built if CUDA is found and `torch.cuda.is_available()` is true. It's possible to force |
| 69 | +building GPU support by setting `FORCE_CUDA=1` environment variable, which is useful when building a docker image. |
| 70 | + |
| 71 | +## Image Backend |
| 72 | + |
| 73 | +Torchvision currently supports the following image backends: |
| 74 | + |
| 75 | +- [Pillow](https://python-pillow.org/) (default) |
| 76 | +- [Pillow-SIMD](https://github.com/uploadcare/pillow-simd) - a **much faster** drop-in replacement for Pillow with SIMD. |
| 77 | + If installed will be used as the default. |
| 78 | +- [accimage](https://github.com/pytorch/accimage) - if installed can be activated by calling |
| 79 | + `torchvision.set_image_backend('accimage')` |
| 80 | +- [libpng](http://www.libpng.org/pub/png/libpng.html) - can be installed via conda `conda install libpng` or any of the |
| 81 | + package managers for debian-based and RHEL-based Linux distributions. |
| 82 | +- [libjpeg](http://ijg.org/) - can be installed via conda `conda install jpeg` or any of the package managers for |
| 83 | + debian-based and RHEL-based Linux distributions. [libjpeg-turbo](https://libjpeg-turbo.org/) can be used as well. |
| 84 | + |
| 85 | +**Notes:** `libpng` and `libjpeg` must be available at compilation time in order to be available. Make sure that it is |
| 86 | +available on the standard library locations, otherwise, add the include and library paths in the environment variables |
| 87 | +`TORCHVISION_INCLUDE` and `TORCHVISION_LIBRARY`, respectively. |
| 88 | + |
| 89 | +## Video Backend |
| 90 | + |
| 91 | +Torchvision currently supports the following video backends: |
| 92 | + |
| 93 | +- [pyav](https://github.com/PyAV-Org/PyAV) (default) - Pythonic binding for ffmpeg libraries. |
| 94 | +- video_reader - This needs ffmpeg to be installed and torchvision to be built from source. There shouldn't be any |
| 95 | + conflicting version of ffmpeg installed. Currently, this is only supported on Linux. |
| 96 | + |
| 97 | +``` |
| 98 | +conda install -c conda-forge ffmpeg |
| 99 | +python setup.py install |
| 100 | +``` |
| 101 | + |
| 102 | +# Using the models on C++ |
| 103 | + |
| 104 | +TorchVision provides an example project for how to use the models on C++ using JIT Script. |
| 105 | + |
| 106 | +Installation From source: |
| 107 | + |
| 108 | +``` |
| 109 | +mkdir build |
| 110 | +cd build |
| 111 | +# Add -DWITH_CUDA=on support for the CUDA if needed |
| 112 | +cmake .. |
| 113 | +make |
| 114 | +make install |
| 115 | +``` |
| 116 | + |
| 117 | +Once installed, the library can be accessed in cmake (after properly configuring `CMAKE_PREFIX_PATH`) via the |
| 118 | +`TorchVision::TorchVision` target: |
| 119 | + |
| 120 | +``` |
| 121 | +find_package(TorchVision REQUIRED) |
| 122 | +target_link_libraries(my-target PUBLIC TorchVision::TorchVision) |
| 123 | +``` |
| 124 | + |
| 125 | +The `TorchVision` package will also automatically look for the `Torch` package and add it as a dependency to |
| 126 | +`my-target`, so make sure that it is also available to cmake via the `CMAKE_PREFIX_PATH`. |
| 127 | + |
| 128 | +For an example setup, take a look at `examples/cpp/hello_world`. |
| 129 | + |
| 130 | +Python linking is disabled by default when compiling TorchVision with CMake, this allows you to run models without any |
| 131 | +Python dependency. In some special cases where TorchVision's operators are used from Python code, you may need to link |
| 132 | +to Python. This can be done by passing `-DUSE_PYTHON=on` to CMake. |
| 133 | + |
| 134 | +### TorchVision Operators |
| 135 | + |
| 136 | +In order to get the torchvision operators registered with torch (eg. for the JIT), all you need to do is to ensure that |
| 137 | +you `#include <torchvision/vision.h>` in your project. |
| 138 | + |
| 139 | +## Documentation |
| 140 | + |
| 141 | +You can find the API documentation on the pytorch website: <https://pytorch.org/vision/stable/index.html> |
| 142 | + |
| 143 | +## Contributing |
| 144 | + |
| 145 | +See the [CONTRIBUTING](CONTRIBUTING.md) file for how to help out. |
| 146 | + |
| 147 | +## Disclaimer on Datasets |
| 148 | + |
| 149 | +This is a utility library that downloads and prepares public datasets. We do not host or distribute these datasets, |
| 150 | +vouch for their quality or fairness, or claim that you have license to use the dataset. It is your responsibility to |
| 151 | +determine whether you have permission to use the dataset under the dataset's license. |
| 152 | + |
| 153 | +If you're a dataset owner and wish to update any part of it (description, citation, etc.), or do not want your dataset |
| 154 | +to be included in this library, please get in touch through a GitHub issue. Thanks for your contribution to the ML |
| 155 | +community! |
| 156 | + |
| 157 | +## Pre-trained Model License |
| 158 | + |
| 159 | +The pre-trained models provided in this library may have their own licenses or terms and conditions derived from the |
| 160 | +dataset used for training. It is your responsibility to determine whether you have permission to use the models for your |
| 161 | +use case. |
| 162 | + |
| 163 | +More specifically, SWAG models are released under the CC-BY-NC 4.0 license. See |
| 164 | +[SWAG LICENSE](https://github.com/facebookresearch/SWAG/blob/main/LICENSE) for additional details. |
| 165 | + |
| 166 | +## Citing TorchVision |
| 167 | + |
| 168 | +If you find TorchVision useful in your work, please consider citing the following BibTeX entry: |
| 169 | + |
| 170 | +```bibtex |
| 171 | +@software{torchvision2016, |
| 172 | + title = {TorchVision: PyTorch's Computer Vision library}, |
| 173 | + author = {TorchVision maintainers and contributors}, |
| 174 | + year = 2016, |
| 175 | + journal = {GitHub repository}, |
| 176 | + publisher = {GitHub}, |
| 177 | + howpublished = {\url{https://github.com/pytorch/vision}} |
| 178 | +} |
| 179 | +``` |
0 commit comments