YOLOE format conversion

Hi,

I*m following Jaryd’s formidable guide on https://core-electronics.com.au/guides/custom-object-detection-models-without-training-yoloe-and-raspberry-pi/ Everything works like clock until the format conversion. Once I run 'Prompt-Free ONNX Conversion.py, I get this error message, no matter which format I try to use:

Traceback (most recent call last):
File “/home/jert/YOLOE/demo_code/YOLOE Run Model.py”, line 2, in
from picamera2 import Picamera2
File “/usr/lib/python3/dist-packages/picamera2/init.py”, line 11, in
from .picamera2 import Picamera2, Preview
File “/usr/lib/python3/dist-packages/picamera2/picamera2.py”, line 30, in
from picamera2.encoders import Encoder, H264Encoder, MJPEGEncoder, Quality
File “/usr/lib/python3/dist-packages/picamera2/encoders/init.py”, line 7, in
from .encoder import Encoder, Quality
File “/usr/lib/python3/dist-packages/picamera2/encoders/encoder.py”, line 13, in
from ..request import _MappedBuffer
File “/usr/lib/python3/dist-packages/picamera2/request.py”, line 13, in
import simplejpeg
File “/usr/lib/python3/dist-packages/simplejpeg/init.py”, line 1, in
from ._jpeg import encode_jpeg, encode_jpeg_yuv_planes
File “simplejpeg/_jpeg.pyx”, line 1, in init simplejpeg._jpeg
ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

What happens? And, of course, how to cure it?

2 Likes

Hey there, @Jerry207389, and welcome to the forum. Glad to have you here.

That error points to a binary compatibility mismatch between NumPy and simplejpeg, which Picamera2 imports.

Could you please confirm which Raspberry Pi OS version are you running, Bookworm or Trixie? Trixie can introduce dependency differences with these guides, so Bookworm is the safer starting point.

Could you also run this in the same Python environment that gives the error and share the output?

import numpy as np
print(np.__version__)

He, and thank you for your reply.
I followed Jaryd’s recipe word-by-word, so it’s Bookworm I use. And the output from the code snippet is 2.4.6.
Obviously, the programs making the format conversion install a newer version of NumPy. Or…?
Regards

Jerry T
Carpe diem!!!

Someone mentioned you in a post.

| Jane
28 October |

  • | - |

Hey there, @Jerry207389, and welcome to the forum. Glad to have you here.

That error points to a binary compatibility mismatch between NumPy and simplejpeg, which Picamera2 imports.

Could you please confirm which Raspberry Pi OS version are you running, Bookworm or Trixie? Trixie can introduce dependency differences with these guides, so Bookworm is the safer starting point.

Could you also run this in the same Python environment that gives the error and share the output?

import numpy as np
print(np.__version__)

Hey there, @Jerry207389,

Thanks for that. I don’t believe that numpy version is right. It’s not in this guide, but there’s a step that sometimes needs to be done. Basically, installing the export dependencies can sometimes end up pulling in a newer NumPy version, which can lead to some compatibility issue.

So we can at least check numpy off the list of culprits, I’ll get you to restore the Numpy version used with this setup guide’s Picamera2 section.

Basically, when using conda you will need to do the following:

# Activate the guide's Conda environment.
source ~/miniforge3/bin/activate
conda activate ultralytics-env

# Restore the NumPy version specified for Bookworm in the guide.
conda install numpy=1.24.2

# Check the version and test the camera-library import.
python -c "import numpy; print(numpy.__version__); from picamera2 import Picamera2; print('Picamera2 import OK')"

If Conda proposes removing Ultralytics or reports conflicting requirements, stop and share that output rather than accepting the changes.

Let us know the results.

Hi,
I downgraded numpy, but it didn’t help.
The snipet
python -c “import numpy; print(numpy.version); from picamera2 import Picamera2; print(‘Picamera2 import OK’)”

reports numpy 2.4.5 and
the same error message as before, ending with

ValueError: numpy.dtype size changed, may indicate binary incompatibility. Expected 96 from C header, got 88 from PyObject

I think I’ll give up. The dependencies are impossible to grasp, Jaryd’s guide is probably outdated, and I suspect I’ll have to struggle all the way trying to make my project to work. I guess I will have to find another solution. Pitty.
And thank you for trying.
Jerry T
Carpe diem!!!

Someone mentioned you in a post.

| Jane
29 October |

  • | - |

Hey there, @Jerry207389,

Thanks for that. I don’t believe that numpy version is right. It’s not in this guide, but there’s a step that sometimes needs to be done. Basically, installing the export dependencies can sometimes end up pulling in a newer NumPy version, which can lead to some compatibility issue.

So we can at least check numpy off the list of culprits, I’ll get you to restore the Numpy version used with this setup guide’s Picamera2 section.

Basically, when using conda you will need to do the following:

# Activate the guide's Conda environment.
source ~/miniforge3/bin/activate
conda activate ultralytics-env

# Restore the NumPy version specified for Bookworm in the guide.
conda install numpy=1.24.2

# Check the version and test the camera-library import.
python -c "import numpy; print(numpy.__version__); from picamera2 import Picamera2; print('Picamera2 import OK')"

If Conda proposes removing Ultralytics or reports conflicting requirements, stop and share that output rather than accepting the changes.

Let us know the results.

Hey, @Jerry207389,

I’m sorry to hear that. I’ll see what we can do about getting the guide updated to stop any potential dependency issue. In the meantime, I hope you find a solution that’s a better fit for your project.

I would be very grateful if you could update the guide. I have no idea how many people use it. I don’t think it will be easy to find another solution for my project, I’ve already tried.

Jerry T
Carpe diem!!!

Someone mentioned you in a post.

| Jane
30 October |

  • | - |

Hey, @Jerry207389,

I’m sorry to hear that. I’ll see what we can do about getting the guide updated to stop any potential dependency issue. In the meantime, I hope you find a solution that’s a better fit for your project.

@Jerry207389, there’s one detail in your traceback that might be worth checking before giving up on the project.

You mentioned running Prompt-Free ONNX Conversion.py, but the traceback actually starts in YOLOE Run Model.py. Could you check which script Thonny is executing?

The other clue is that Picamera2 and simplejpeg are being imported from /usr/lib/python3/dist-packages/, while you’ve been changing NumPy inside a Conda environment.

That can cause exactly this kind of binary compatibility problem if the interpreter loads NumPy 2.x alongside a system-installed extension built against an older NumPy version.

What stands out to me is that after installing NumPy 1.24.2, your test still reported 2.4.5. So before changing any more packages, I’d check which Python executable and NumPy installation are actually being used.

Could you run this in the same environment where the error happens?

import sys
import numpy
import importlib.util

print("Python:", sys.executable)
print("NumPy version:", numpy.__version__)
print("NumPy location:", numpy.__file__)
print("simplejpeg location:", importlib.util.find_spec("simplejpeg").origin)

If you’re using Thonny, run it there too, since Thonny may be configured to use a different interpreter from your terminal.

I’d avoid reinstalling system-wide NumPy or simplejpeg until those paths are clear. Otherwise you could end up breaking the Raspberry Pi camera packages while trying to fix the YOLO environment.

The fact that NumPy remained at 2.4.5 after the downgrade is probably the most useful clue at this point.