3

I sent a Raspberry Pi to use the training file with yolov8. While the computer codes were working without any errors, I got an error on the Raspberry Pi. I got an "illegal instruction" error when installing ultralytics from the very beginning. In my research I found that torch and torchvision would have the same errors.

Used card: Raspberry Pi 3B+, Raspbian 64 Bit OS, Python 3.9.2,

Why does it work on my computer, not on raspberry?

enter image description here

I will be glad if you help.

from ultralytics import YOLO
import supervision as sv
import cv2

cap = cv2.VideoCapture(0)
model = YOLO(r"train/best.pt")

box_a = sv.BoxAnnotator(

    thickness=2,

    text_thickness=2,

    text_scale=1
)
while True:

    ret,frame = cap.read()

    sonuc=model(source=frame, agnostic_nms=True)[0]

    detection = sv.Detections.from_yolov8(sonuc)
    labels = [

        f"{model.model.names[class_id]}{confidence:0.2f}"
        for _,confidence,class_id,_
        in detection

    ]

    frame = box_a.annotate(
        scene=frame,
        detections=detection,
        labels=labels
    )
    # Dur için = 0, Düz Git = 1, İnsan = 2, Sağ Dön = 3, Sola Dön = 4

    if len(detection.class_id)>0:

        x = detection.class_id[0]
        x1, y1, x2, y2 = int(detection.xyxy[0, 0]), int(detection.xyxy[0, 1]), int(detection.xyxy[0, 2]), int(
            detection.xyxy[0, 3])
        width = x2 - x1
        if width>180:
            if x == 0 and width>180:
                #Dur levhasını tanımıştır.
                pass

            elif x == 1:
                # Düz git levhası
                pass

            elif x ==2:
                # İnsan figürü
                pass

            elif x==3:
                # Sağa dön levhası
                pass

            elif x==4:
                # Sola dön levhası
                pass

            else:
                pass


    cv2.imshow("Deneme",frame)
    if cv2.waitKey(20) &0XFF==ord("q"):

        break
cap.release()

cv2.destroyAllWindows()

I install pytorch 1.13, torchvision, ultralytics git page but dont work on raspberry pi, while work on computer.

toyota Supra
  • 3,181
  • 4
  • 15
  • 19

1 Answers1

2

First of all, I am not sure on the reason of it. I read somewhere that it is about some instructions added with ARMV8.2 architecture. But i know the solution of it.

Downgrade torch to 1.12

pip install torch==1.12.0

and after that you will get an error indicating that torchvision is incompatible so you downgrade it to the compatible torchvision 0.13.0. You can chenck it up from the compatibility table from the link https://pypi.org/project/torchvision/

pip install torchvision==0.13.0

Make sure that python version is compatible as well. In your case 3.9.2 should be fine.

This method worked on my RPI4.