RuntimeError: decode_jpeg_cuda: torchvision not compiled with nvJPEG support on Jetson AGX Orin Development Kit (Jetpack 5.1.2)

torchvision supports decoding jpeg image via nvjpeg but I get an error when using it on Jetson AGX Orin development kit

Code

import torch
import torchvision
device = torch.device("cuda")
img_path = "path_to_your_image"
img_cpu = torchvision.io.read_file(img_path)
img_gpu = torchvision.io.decode_jpeg(img_cpu, device=device)

Error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/dist-packages/torchvision/io/image.py", line 168, in decode_jpeg
    output = torch.ops.image.decode_jpeg_cuda(input, mode.value, device)
  File "/usr/local/lib/python3.8/dist-packages/torch/_ops.py", line 502, in __call__
    return self._op(*args, **kwargs or {})
RuntimeError: decode_jpeg_cuda: torchvision not compiled with nvJPEG support

Container Used: dustynv/l4t-pytorch:r35.4.1

I suspect while building torchvision, it was unable to find nvjpeg. This might be because it is trying to look for nvjpeg in CUDA_HOME (/usr/local/cuda) which is true of x86 based systems but not for Jetson’s I guess. I ran the find command to find “nvjpeg.h” but was unable to find its location on the Orin. Could you help with this issue? I would like build torchvision with nvJPEG as it helps loads image faster instead of loading image via CPU using opencv and then moving to GPU

Snippet of code used to build torchvision to find nvjpeg

    nvjpeg_found = (
        extension is CUDAExtension
        and CUDA_HOME is not None
        and os.path.exists(os.path.join(CUDA_HOME, "include", "nvjpeg.h"))
    )

Link to Issue Raised on Github

Hi,
Please refer to the explanation in
RuntimeError: decode_jpeg_cuda: torchvision not compiled with nvJPEG support on Jetson AGX Orin Development Kit (Jetpack 5.1.2) · Issue #446 · dusty-nv/jetson-containers · GitHub

nvJPEG

For hardware JPEG decoding on Jetson platforms, please try NvJpegDecoder. You can check this sample:

/usr/src/jetson_multimedia_api/samples/06_jpeg_decode/

Hi @DaneLLL

Thank you, I tried compiling this example but it fails. It is unable to find vulkan.h. Please suggest ways I could go about solving this issue

make[1]: Entering directory '/usr/src/jetson_multimedia_api/samples/common/classes'
Compiling: NvVulkanRenderer.cpp
In file included from NvVulkanRenderer.cpp:29:
/usr/src/jetson_multimedia_api/include/NvVulkanRenderer.h:43:10: fatal error: vulkan/vulkan.h: No such file or directory
   43 | #include <vulkan/vulkan.h>
      |          ^~~~~~~~~~~~~~~~~
compilation terminated.
make[1]: *** [Makefile:41: NvVulkanRenderer.o] Error 1
make[1]: Leaving directory '/usr/src/jetson_multimedia_api/samples/common/classes'
make: *** [Makefile:45: /usr/src/jetson_multimedia_api/samples/common/classes/NvVulkanRenderer.o] Error 2

Hi,
We don’t observe the issue. Do you install the reference samples through SDKManager or sudo apt-get install command? The dependency should be handled in both methods.

Would suggest check why you don’t have the files. But you can modify Makefile to remove building NvVulkanRenderer. It is not used in 06_jpeg_decode sample.

I am sharing the makefile below, I do not see any NvVulkanRenderer mentioned. I tried removing $(wildcard $(CLASS_DIR)/*.cpp) but it failed during linking.

How do you suggest I check why I don’t have that file? Could you also suggest a way to install just vulkan? I would prefer not to flash my jetson again, takes too much setup time

include ../Rules.mk

APP := jpeg_decode

SRCS := \
	jpeg_decode_csvparser.cpp \
	jpeg_decode_main.cpp \
	$(wildcard $(CLASS_DIR)/*.cpp)

OBJS := $(SRCS:.cpp=.o)

all: $(APP)

$(CLASS_DIR)/%.o: $(CLASS_DIR)/%.cpp
	$(AT)$(MAKE) -C $(CLASS_DIR)

%.o: %.cpp
	@echo "Compiling: $<"
	$(CPP) $(CPPFLAGS) -c $<

$(APP): $(OBJS)
	@echo "Linking: $@"
	$(CPP) -o $@ $(OBJS) $(CPPFLAGS) $(LDFLAGS)

clean:
	$(AT)rm -rf $(APP) $(OBJS)

@DaneLLL Any help on this issue would be greatly appreciated

@DaneLLL I tried building the NvJPEG examples in the L4T-Jetpack container (nvcr.io/nvidia/l4t-jetpack:r35.4.1) and got a similar error of vulkan.h not found

Hi,
We would suggest re-flash AGX Orin developer kit to Jetpack 5.1.3 and re-install the samples through SDKManager. It is supported to be working fine on a clean system.

Just ran apt-get update & apt-get upgrade and it’s working now but doesn’t work inside the container.