I’m trying to convert a custom YOLOv8n model to .rpk for the Sony IMX500 and running into two main issues.
My pipeline is: PyTorch → packerOut.zip from Sony MCT → RPK using imx500-package.
The conversion finishes without errors and the model loads onto the camera, but when I run it:
I get a tensor mismatch error: ValueError: tensor info length 708 does not match expected size 712
All the confidence scores come out as 0.0.
Class IDs do show up sometimes, and the exact same model works fine in PyTorch, so something is getting messed up during conversion/quantization.
All my Sony/MCT tools should be up to date:
sony-custom-layers: 0.3.0
mct-quantizers: 1.6.0
imx500-converter: 3.17.3
model-compression-toolkit: 2.4.4
So I don’t think this is an outdated tools issue.
Has anyone here actually gotten YOLOv8 running on the IMX500 recently? Not sure if this is:
some firmware or picamera2 version mismatch
YOLOv8 not playing nice with INT8 for this chip
or me missing something in the conversion flow
Setup: Raspberry Pi 5, IMX500 camera, picamera2 v0.3.31.
If anyone’s run into this or has YOLOv8n models working on the IMX500, would really appreciate any pointers.
I tried following those exact steps, and no matter what happens when I finally get to running the code I get an error saying no module named libcamera._libcamera. (Due to 2 link limit some of these just say “GitHub link”)
Then check that python 3.11.6 successfully installed by running python3.11 --version
Then, on your raspberry pi, run this:
git clone -b next picamera2 GitHub link
cd picamera2
pip3.11 install -e . --break-system-packages
Then run this:
pip3.11 install --break-system-packages git+aitrios library GitHub link
Then run:
python3.11 (file referencing modlib).py
and that’s where I get the error saying no module named libcamera._libcamera. I can’t do pip3.11 install rpi-libcamera because it says the version of libcamera installed on the system is different from the one it requires
You should always install packages using a Python virtual environment. See this article for more info.
Before installing your packages, run
python3 -m venv .venv
this will create a virtual environment. Then you can run
source .venv/bin/activate
to activate the virtual environment. When you do this, packages you install when the environment is activated will be isolated from the system packages and/or other projects. There’s nothing wrong with using pip to install Python packages, but you should consider using uv as it’s faster and can help manage virtual environments (and Python installs), which helps considerably when setting up projects.
Additionally, it appears that picamera2 is currently in beta, so not sure that’s what you want to install, it’s also not shown in the IMX export setup on the Ultralytics documentation page. Finally, you probably want to have libcamera as per the Raspberry Pi documentation which is listed as usable with the Sony IMX 500, but this should be included with the Raspberry Pi OS distribution, so you shouldn’t have to install anything. Breaking the system packages could mean that the libcamera install is broken and that you may need to reflash the OS.
So the problem is that my raspberry PI OS runs python 3.13 by default, and libcamera seems to be working fine on 3.13. I do face that same tensor error OP did, but that’s unrelated to libcamera. And aitrios’ modlib only supports python 3.11 or below. So I don’t know what to do.
I don’t think libcamera is broken, because I can run rpicam-hello -t 0s --post-process-file /usr/share/rpi-camera-assets/imx500_mobilenet_ssd.json --viewfinder-width 1920 --viewfinder-height 1080 --framerate 30
You’re right that these are two separate issues: the libcamera._libcamera import problem and the tensor‑size error. Let’s untangle them.
For the libcamera / Python version problem: the Sony Aitrios modlib stack is only tested against Python ≤3.11, and our IMX500 guide was validated on Raspberry Pi OS Bookworm with Python 3.11 as the system Python, as described in the Sony IMX500 export guide. On your image with Python 3.13 as the default, the libcamera Python bindings are built for 3.13, so a hand‑compiled 3.11 interpreter has no matching libcamera._libcamera extension, which is exactly the error you’re seeing.
Practically, the reliable path today is to run your IMX500 runtime scripts on a Raspberry Pi OS image where Python 3.11 is the system version (e.g. the standard Bookworm image Sony and Raspberry Pi document), and install only imx500-all plus the aitrios-rpi-application-module-library into a virtual environment. Mixing a 3.13 system with a custom 3.11 almost always leads to the binding mismatch you hit; there isn’t a clean workaround unless Raspberry Pi ship libcamera bindings for both versions.
Once you’re on a 3.11‑based OS and the Aitrios examples run cleanly, if you still see the tensor mismatch error, please share the exact yolo export command and model you used. IMX export in Ultralytics uses a fixed Sony MCT config for supported models (YOLOv8n and YOLO11n detect/pose) via model.export(format="imx", data=...), as shown in the IMX500 usage examples, and that should avoid the 708 vs 712 tensor‑length issue you and the OP are seeing.
Thank you! Switching to Bookworm fixed the problem. The tensor error is irrelevant if the ultralytics code works. That was just me trying to run the code Raspberry Pi provided.
We only recommend you to use Bookworm OS (default Python 3.11) at the moment because we do not currently have full support for Trixie OS (default Python 3.13).
The current IMX documentation is written and validated specially for Bookworm OS running Python 3.11. We will try to bring Python 3.13 support for this export in the future.