Cannot compile TorchVision 0.16

I tried to install PyTorch 2.1.0 with TorchVision 0.16 on Jetson Xavier AGX with JetPack 5.1.2.

I followed the instructions from this page to install PyTorch inside a virtual environment. Installation was successful.

I then tried to install the matching version of TorchVision, i.e. versoin 0.16. I followed below steps:

$ sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev

$ git clone --branch release/0.16 https://github.com/pytorch/vision torchvision

$ cd torchvision

$ export BUILD_VERSION=0.16.0

$ python3 setup.py install --user

Unfortunately build fails with following error:

/home/nvidia/repos/torchvision/torchvision/csrc/io/decoder/stream.cpp:68:42: error:
‘AV_CODEC_CAP_INTRA_ONLY’ was not declared in this scope; did you mean ‘AV_CODEC_PROP_INTRA_ONLY’?
68 | if (codecCtx_->codec->capabilities & AV_CODEC_CAP_INTRA_ONLY) {
| ^~~~~~~~~~~~~~~~~~~~~~~
| AV_CODEC_PROP_INTRA_ONLY
error: command ‘aarch64-linux-gnu-gcc’ failed with exit status 1

Hi,

It looks like you are facing a similar issue as the below link.
Could you give it a check?

Thanks.

I have applied the fix mentioned in the link that you shared and tried to build again. I now get another error:

/usr/bin/ld: /usr/local/lib/libavutil.a(tx_float_neon.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol ff_tx_tab_65536_float' which may bind externally can not be used when making a shared object; recompile with -fPIC /home/nvidia/Downloads/build/code/ffmpeg/libavutil/aarch64/tx_float_neon.S:1294:(.text+0xaea0): dangerous relocation: unsupported relocation /usr/bin/ld: /usr/local/lib/libavutil.a(tx_float_neon.o): relocation R_AARCH64_ADR_PREL_PG_HI21 against symbol ff_tx_tab_131072_float’ which may bind externally can not be used when making a shared object; recompile with -fPIC
/home/nvidia/Downloads/build/code/ffmpeg/libavutil/aarch64/tx_float_neon.S:1294:(.text+0xb4c8): dangerous relocation: unsupported relocation
collect2: error: ld returned 1 exit status
error: command ‘aarch64-linux-gnu-g++’ failed with exit status 1

Hi,

Just give it a try on JetPack 5.1.2.
The building can work correctly without the two error you met.

Please check our building command below:

$ sudo apt-get -y install python3-pip libopenblas-dev;
$ sudo apt-get install libjpeg-dev zlib1g-dev libpython3-dev libavcodec-dev libavformat-dev libswscale-dev
$ python3 -m pip install --no-cache https://developer.download.nvidia.com/compute/redist/jp/v512/pytorch/torch-2.1.0a0+41361538.nv23.06-cp38-cp38-linux_aarch64.whl
$ git clone --branch release/0.16.1 https://github.com/pytorch/vision torchvision
$ cd torchvision/
$ export BUILD_VERSION=0.16.1
$ python3 setup.py install --user
Building wheel torchvision-0.16.1
Compiling extensions with following flags:
  FORCE_CUDA: False
  FORCE_MPS: False
  DEBUG: False
  TORCHVISION_USE_PNG: True
  TORCHVISION_USE_JPEG: True
  TORCHVISION_USE_NVJPEG: True
  TORCHVISION_USE_FFMPEG: True
  TORCHVISION_USE_VIDEO_CODEC: True
  NVCC_FLAGS: 
Compiling with debug mode OFF
...

Using /usr/local/lib/python3.8/dist-packages
Finished processing dependencies for torchvision==0.16.1

Thanks.

I have already tried the steps you mention in other Xavier AGX boxes that I own with JetPack 5.1.2. In all cases up to now PyTorch / Torchvision installation was successful.

BUT, in the current AGX box, where the issue appears, I followed the exact same steps. Despite previous successful installations in the other boxes the issues mentioned in my post appeared.

I think the issue is due to ffmpeg. Was ffmpeg v 6.0 installed on your system when you tried to build?

I just noticed that you are cloning a slightly different version. I tried above command but I get following response:

$ git clone --branch release/0.16.1 https://github.com/pytorch/vision torchvision
Cloning into 'torchvision'...
fatal: Remote branch release/0.16.1 not found in upstream origin

Hi,

Sorry, it should be v0.16.1:

git clone --branch v0.16.1 https://github.com/pytorch/vision torchvision

We test it with the default ffmpeg from apt and it can work as well.

$ ffmpeg -version
ffmpeg version n4.2.7-24-gd796def2ea-1ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2)
configuration: --prefix=/usr --enable-nvv4l2dec --enable-libv4l2 --enable-shared --extra-libs='-L/usr/lib/aarch64-linux-gnu/tegra -lv4l2 -lnvbufsurface -lnvbufsurftransform' --extra-cflags=-I/usr/src/jetson_multimedia_api/include/ --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --arch=arm64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 31.100 / 56. 31.100
libavcodec     58. 54.100 / 58. 54.100
libavformat    58. 29.100 / 58. 29.100
libavdevice    58.  8.100 / 58.  8.100
libavfilter     7. 57.100 /  7. 57.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  5.100 /  5.  5.100
libswresample   3.  5.100 /  3.  5.100
libpostproc    55.  5.100 / 55.  5.100

TorchVision:

$ python3 setup.py install --user
Building wheel torchvision-0.16.1
...
Building torchvision with ffmpeg support
  ffmpeg version: b"ffmpeg version n4.2.7-24-gd796def2ea-1ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers\nbuilt with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.2)\nconfiguration: --prefix=/usr --enable-nvv4l2dec --enable-libv4l2 --enable-shared --extra-libs='-L/usr/lib/aarch64-linux-gnu/tegra -lv4l2 -lnvbufsurface -lnvbufsurftransform' --extra-cflags=-I/usr/src/jetson_multimedia_api/include/ --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/aarch64-linux-gnu --incdir=/usr/include/aarch64-linux-gnu --arch=arm64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared\nlibavutil      56. 31.100 / 56. 31.100\nlibavcodec     58. 54.100 / 58. 54.100\nlibavformat    58. 29.100 / 58. 29.100\nlibavdevice    58.  8.100 / 58.  8.100\nlibavfilter     7. 57.100 /  7. 57.100\nlibavresample   4.  0.  0 /  4.  0.  0\nlibswscale      5.  5.100 /  5.  5.100\nlibswresample   3.  5.100 /  3.  5.100\nlibpostproc    55.  5.100 / 55.  5.100\n"
  ffmpeg include path: ['/usr/include', '/usr/include/aarch64-linux-gnu']
  ffmpeg library_dir: ['/usr/lib', '/usr/lib/aarch64-linux-gnu']
...
Using /usr/local/lib/python3.8/dist-packages
Finished processing dependencies for torchvision==0.16.1

Thanks.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.