Rate This Document
Findability
Accuracy
Completeness
Readability

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.

  1. 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
    
  2. Run the python setup.py install command to install PyTorch.
    Before the installation, check the Python version requirements of PyTorch. For details, visit the PyTorch official website.
    1
    python setup.py install
    
  3. 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.

  1. Use git to clone the source repository of TorchVision.
    1
    git clone -b v0.20.0 https://github.com/pytorch/vision.git
    
  2. In the vision directory, run the python setup.py develop --cmake command to install TorchVision.
    1
    2
    cd vision
    python setup.py develop --cmake
    
  3. 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.

When installing TorchVision, pay attention to the PyTorch version requirements of the current TorchVision version. For details, go to https://pypi.org/project/torchvision/.

Using the PyTorch Image Operator

  1. Decompress the KPCV software package BoostKit-kp_cv_***.zip to obtain kpt-2.4.1.patch and kpt.patch.
  2. 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
    
  3. 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.

    Solution: Add errors='ignore' to the open function in the cmake.py and env.py files in the torch/tools/setup_helpers directory. See Figure 1 and Figure 2.
    Figure 1 cmake.py
    Figure 2 env.py