Yolov5 on the Jetpack 5.0.2 - ValueError: axes don't match array

Hi Jetson community,

Has anyone experienced the problem like below, when running detect.py using camera source?

[ WARN:0] global /home/jetson/opencv/modules/videoio/src/cap_gstreamer.cpp (1100) open OpenCV | GStreamer warning: Cannot query video position: status=0, value=-1, duration=-1
1/1: 2...  Success (inf frames 1280x720 at 30.00 FPS)

Traceback (most recent call last):
  File "detect.py", line 254, in <module>
  File "detect.py", line 249, in main
  File "/home/jetson/.local/lib/python3.8/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
    return func(*args, **kwargs)
  File "detect.py", line 111, in run
    for path, im, im0s, vid_cap, s in dataset:
  File "/home/jetson/Projects/yolo/yolov5/utils/dataloaders.py", line 396, in __next__
    img = img[..., ::-1].transpose((0, 3, 1, 2))  # BGR to RGB, BHWC to BCHW
ValueError: axes don't match array
FATAL: exception not rethrown
Aborted (core dumped)


It looks like there is a typo in your script

    img = img[..., ::-1].transpose((0, 3, 1, 2))  # BGR to RGB, BHWC to BCHW

Please use a validated index and try it again.


Hi @AastaLLL, thanks for your reply. Last week, when I was using Jetpack 4.6 with pytorch 1.8.0, it was working fine, since these are original yolov5 files from github repository. When I upgraded jetpack 5.0.2, I was able to solve my multiple previous issues for example TensorRT and espnet packages, but it created another issues for example here and Vscode is not working at all on jetpack 5.0.2)))))can’t explain it

Hi @AastaLLL, Let me apologize, my mistake, I was using realsense camera d435, when it was jeppack 4.6, the camera index of RGB was 2, now it became 4. So when I used camera index 2 with jetpack 5.0.2, it was initiating infrared camera. Do you know why it was changed?


Do you mean the camera is mounted to /dev/video4?
If yes, it looks like you can change it by modifying the input argument.


Hi @AastaLLL, that is a real-sense camera from Intel, it combines multiple cameras. To test my object detection applications, i was using RGB camera. Since I upgraded my jetpack to 5.0.2, a camera index of RGB camera was changed from 2 to 4.

I’m closing this topic due to there is no update from you for a period, assuming this issue was resolved.
If still need the support, please open a new topic. Thanks


It should be okay.
Do you get the sample work after updating the source index?


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