I am currently trying to use yolov8 to perform object detection on the raspberry pi 4. I have installed ultralytics and other necessary packages but whenever i run the code on the terminal it says "segmentation fault". Here is the code that I am trying to run:

from ultralytics import YOLO
model = YOLO("yolov8n.pt")
model.predict(source=0, show=True)

How can I fix this error?

  • Segmentation fault means that some native code has tried to manipulate memory unavailable to it. Typically this is because of unhandled invalid input data. Are you certain your code provides all the parameters needed and that they are as expected. If you follow a tutorial it may be outdated. Oct 5 at 21:00
  • Solve this is something yolov8 can do, NOT Raspberry Pi.
    – MatsK
    Oct 7 at 9:20
  • It is showinh me this error message: "WARNING ⚠️ inference results will accumulate in RAM unless stream=True is passed, causing potential out-of-memory errors for large sources or long-running streams and videos." I have included the stream=True but i still keep getting the message
    – Eme Obioh
    Oct 7 at 12:19
  • Might be useful if you posted the full text of the seg fault.
    – goldilocks
    Oct 18 at 13:41

2 Answers 2


Downgrading torch and torchvision worked for me.

pip uninstall torch torchvision
pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2

You can read more about this issue at https://github.com/ultralytics/ultralytics/issues/5274


Try this!

from ultralytics import YOLO

model = YOLO("yolov8n.pt")

results = model.predict(source=0, stream=True)

for r in results:
    boxes = r.boxes  # Bounding box coordinates
    masks = r.masks  # Segmentation masks
    probs = r.probs  # Class probabilities
  • @goldilocks Thanks for the reply. I tried what you suggested and this is what i get: 1/1: 0... Success ✅ (inf frames of shape 640x480 at 30.00 FPS) Segmentation fault The segmentation fault error is still there and the video does not even show
    – Eme Obioh
    Oct 19 at 19:54
  • I didn't suggest anything, I just formatted the code in Sam's answer.
    – goldilocks
    Oct 19 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.