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()
- predict can not using threads?
- 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?