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 Conda and Related Dependencies

  1. Download the installation script Miniconda3-py312_25.1.1-2-Linux-aarch64.sh.
  2. Execute the script and press Enter or type yes as prompted.
    1
    2
    bash Miniconda3-py312_25.1.1-2-Linux-aarch64.sh
    source /root/miniconda3/bin/activate
    
  3. Enter the conda environment.
    conda activate base
  4. Install the dependencies.
    1
    2
    3
    4
    5
    conda install cmake ninja numpy pyyaml typing_extensions pillow fsspec jinja2 networkx sympy filelock ffmpeg
    # Conda cannot install complete GCC and g++, and GCC libraries in the system environment are required. Therefore, the GCC version and g++ major version installed via Conda must be the same as those in the system environment.
    # For example, you can run the gcc -V command to check the version. If the GCC version is 12, run the following commands:
    conda install -c conda-forge gcc=12 gxx=12
    pip install av==11.0.0 pytest
    
  5. Configure the environment variable.
    1
    export LD_LIBRARY_PATH=/root/miniconda3/lib:${LD_LIBRARY_PATH}
    

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 pytorch-v2.4.1.tar.gz.
  2. Perform compilation and installation.
    Before the installation, check the Python version requirements of PyTorch on the official PyTorch website.
    1
    2
    3
    tar -xzvf pytorch-v2.4.1.tar.gz && cd pytorch-v2.4.1 && git init && git add . && git commit -m "init"
    python setup.py build --cmake
    python setup.py install
    
  3. Open the Python terminal and enter the following code to check whether PyTorch is installed: Note: Do not run the commands in the pytorch-v2.4.1 source code path. Use another path instead.
    1
    2
    import torch
    print(torch.__version__)
    

    If the PyTorch version is displayed, PyTorch has been installed.

Installing TorchVision

Before the installation, ensure that PyTorch has been installed.

  1. Download the TorchVision source code v0.20.0.zip.
  2. Perform compilation and installation.
    1
    2
    unzip vision-0.20.0.zip && cd vision-0.20.0 && git init && git add . && git commit -m "init"
    python setup.py install
    
  3. Open the Python terminal and enter the following code to check whether TorchVision is installed: Note: Do not run the commands in the vision-0.20.0 source code path. Use another path instead.
    1
    2
    import torchvision
    print(torchvision.__version__)
    

    If the TorchVision version is displayed, TorchVision has been installed.

Using the PyTorch Image Operator

  1. Decompress the KPCV software package BoostKit-kp_cv_***.zip to obtain kpt-2.4.1.patch, kpt.patch, and vision-0.20.0.patch.
  2. Apply the kpt-2.4.1.patch file in the PyTorch source code directory. This patch is required for optimizing the resize function.
    1
    2
    git apply kpt-2.4.1.patch
    python setup.py install
    
  3. Apply patch files in the TorchVision source code directory.
    • Apply the kpt.patch file to optimize the normalize and permute functions.
      1
      2
      git apply kpt.patch
      python setup.py install
      
    • Apply the vision-0.20.0.patch file to optimize the crop and write_video functions.
      1
      2
      git apply vision-0.20.0.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 pytorch-v2.4.1/tools/setup_helpers directory. See Figure 1 and Figure 2.
    Figure 1 cmake.py
    Figure 2 env.py
  • Problem 3: "undefined reference to `__cxa_thread_atexit_impl@GLIBC_2.18'" is displayed during PyTorch compilation.

Solution:

export CC=/usr/bin/gcc
export CXX=/usr/bin/g++