Installation and Usage Description
Before calling PyTorch image operator interfaces, configure the PyTorch and TorchVision environments and apply the required patch file.
Installing PyTorch 2.4.1
PyTorch dependencies include Python, pip, CMake, and other libraries. Before the installation, ensure that the dependencies have been installed.
- Download the PyTorch source code and related third-party dependencies. You can use the --recursive option of git. (v2.4.1 is required.)
1 2 3 4
git clone -b v2.4.1 https://github.com/pytorch/pytorch --depth=1 pytorch cd pytorch git submodule sync git submodule update --init --recursive
- Run the python setup.py install command to install PyTorch.
- Open the Python terminal and enter the following code to check whether PyTorch is installed:
1 2
import torch print(torch.__version__)
If the PyTorch version is displayed, PyTorch has been installed.
The dependency packages are stored in the requirement.txt file in the same directory as setup.py. By default, setup.py directly installs these packages through the pip install command. If the download fails, you can run the following command to install the dependency packages.
pip install -r requirements.txt
Installing TorchVision
Before the installation, ensure that PyTorch has been installed.
- Use git to clone the source repository of TorchVision.
1git clone -b v0.20.0 https://github.com/pytorch/vision.git
- In the vision directory, run the python setup.py develop --cmake command to install TorchVision.
1 2
cd vision python setup.py develop --cmake
- Open the Python terminal and enter the following code to check whether TorchVision is installed:
1 2
import torchvision print(torchvision.__version__)
If the TorchVision version is displayed, TorchVision has been installed.
Using the PyTorch Image Operator
- Decompress the KPCV software package BoostKit-kp_cv_***.zip to obtain kpt-2.4.1.patch and kpt.patch.
- Apply the kpt-2.4.1.patch file in the PyTorch source code directory.
1 2
git apply kpt-2.4.1.patch python setup.py build
- Apply the kpt.patch file under the TorchVision source code directory.
1 2
git apply kpt.patch python setup.py install
After the patch is applied, the PyTorch image operator can be used.
Troubleshooting
- Problem 1: During the installation, a message is displayed indicating that the immintrin.h header file cannot be found.
Solution: Install python-devel.
- Problem 2: "'utf-8' codec can't decode byte 0xe0 in position 5560: invalid continuation byte" is displayed during the installation.

Parent topic: PyTorch Image Operators

