Index Error during inference Using Roboflow Docker with cv2 using Picamera2

I’m pretty new to this so please bare with me, I’m using the roboflow library and cv2 library for my object detection model that I’m using with a docker with a raspberry pi, but I’m getting this error and trying to think what should be my next move. Anyone knowledgeable could be a great help since this is for my thesis study.

import cv2
import time
from picamera2 import Picamera2
from inference import InferencePipeline
from roboflow import Roboflow
import pandas as pd
import cvzone
import numpy as np

picam2a = Picamera2(0)
picam2b = Picamera2(1)

picam2a.preview_configuration.sensor.output_size = (640,480)
picam2b.preview_configuration.sensor.output_size = (640,480)

picam2a.preview_configuration.sensor.bit_depth = 10
picam2b.preview_configuration.sensor.bit_depth = 10

picam2a.preview_configuration.main.format = "RGB888"
picam2b.preview_configuration.main.format = "RGB888"

picam2a.preview_configuration.controls.FrameRate = 30
picam2b.preview_configuration.controls.FrameRate = 30

picam2a.configure("preview")
picam2b.configure("preview")

picam2a.start()
picam2b.start()

rf = Roboflow(api_key="~~~~~~~~~~~")
project = rf.workspace().project("~~~~~~~~~~~")
model = project.version(3, local="http:~~~~~~~~~~~~~/").model
classes = ['Ripe','Unripe','Overripe']
data = classes
class_list = data
count=0

fps = 0

while True:
    tStart = time.time()
    im= picam2a.capture_array()
    im2= picam2b.capture_array()

    count += 1
    if count % 3 != 0:
        continue
    im=cv2.flip(im,0) # type: ignore
    prediction=model.predict(im,confidence=40, overlap=30)
    print(prediction.json())
    a=prediction[0].boxdata
    px=pd.DataFrame(a).astype("float")

    for index,row in px.iterrows():
#        print(row)

        x1=int(row[0])
        y1=int(row[1])
        x2=int(row[2])
        y2=int(row[3])
        d=int(row[5])
        c=class_list[d]
        
        cv2.rectangle(im,(x1,y1),(x2,y2),(0,0,255),2)
        cvzone.putTextRect(im,f'{c}',(x1,y1),1,1)
    cv2.imshow("Camera1", im)

    im2=cv2.flip(im2,0) # type: ignore
    prediction=model.predict(im2, confidence=40, overlap=30)
    print(prediction.json())
    a=prediction[0].boxdata
    px=pd.DataFrame(a).astype("float")
    
    for index,row in px.iterrows():
#        print(row)
 
        x1=int(row[0])
        y1=int(row[1])
        x2=int(row[2])
        y2=int(row[3])
        d=int(row[5])
        c=class_list[d]
        
        cv2.rectangle(im2,(x1,y1),(x2,y2),(0,0,255),2)
        cvzone.putTextRect(im2,f'{c}',(x1,y1),1,1)
    cv2.imshow("Camera2", im2)
    
    if cv2.waitKey(30)==ord('q'):
        break
    tEnd = time.time()
    loopTime = tEnd-tStart
    fps = .9*fps + .1*(1/loopTime)
    print(int(fps))
cv2.destroyAllWindows()

This is the code I’ve been building and I’ve tested using YOLO before and it works just fine but I’ve had some trouble training my data with my local machine so I’ve transfered to the Roboflow docker instead and here’s the output error I’ve getting.

File "/home/ACSIPGuro/rpi-bookworm-yolov8/cam_3.py", line 53, in <module>
    a=prediction[0].boxdata
      ~~~~~~~~~~^^^
  File "/home/ACSIPGuro/.local/lib/python3.11/site-packages/roboflow/util/prediction.py", line 421, in __getitem__
    return self.predictions[index]
           ~~~~~~~~~~~~~~~~^^^^^^^
IndexError: list index out of range

I’ve tried removing these lines and it works but the boxes that shows what it detects are not showing if I don’t define the box frames.

 a=prediction[0].boxdata
    px=pd.DataFrame(a).astype("float")
    
    for index,row in px.iterrows():
#        print(row)
 
        x1=int(row[0])
        y1=int(row[1])
        x2=int(row[2])
        y2=int(row[3])
        d=int(row[5])
        c=class_list[d]
        
        cv2.rectangle(im2,(x1,y1),(x2,y2),(0,0,255),2)
        cvzone.putTextRect(im2,f'{c}',(x1,y1),1,1)

Anyone have other ways of doing this or any other alternatives? Thanks in advance!

New contributor

geekbird is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật