I want precdict threading

I want to perform inference on an array of 500 images using threads.

Ask AI said to use it thie way

but, this code Thread collision error

-> not use predict Thread error

from threading import Thread
from ultralytics import YOLO

imagearray = [1.jpg,2.jpg...500.jpg]
imagearray2 = [501.jpg,502.jpg...1000.jpg]

def thread_safe_predict(image_path):
    # train model-> best.pt 
    model = YOLO("best.pt") 
    model.to('cpu')
    results = model.predict(image_path)

# Start concurrent threads
Thread(target=thread_safe_predict, args=(imagearray)).start()
Thread(target=thread_safe_predict, args=(imagearray2)).start()
  1. predict can not using threads?
  2. Loading images over the network is slow, so I plan to use threads to process two inferences simultaneously. I am wondering if this approach is effcient. EX) 500 images: predict time → 2:50 two thread (500 images, 500images) prdict time → 2:50 Is this possible?

Please let me know if there are any methods other than performing parallel inference when image loading is slow.

Can you explain your use case?

Threading in Python wouldn’t improve speed of inference because you’re still using the same CPU and GPU. Two simultaneous inference would just make both slower.