yolov5-tensorrt icon indicating copy to clipboard operation
yolov5-tensorrt copied to clipboard

Support running in parallel in python multithreading

Open PhuongNDVN opened this issue 1 year ago • 0 comments

I try to run the project in python multithreading. The total processing time is similar to running in serial. I tried to modify pybind.cpp with pybind11::call_guard pybind11::gil_scoped_release () but no effect. What I've tried:

  pybind11::gil_scoped_release release;
  const Result r = detector.detectBatch(mats, &detections, flags);
  pybind11::gil_scoped_acquire acquire;

Plz consider this issue.

The code I tested with multithreading:

from threading import Thread
ts = time.perf_counter()
num_of_threads = 3
threads = []
for k in range(num_of_threads):
    thread = Thread(target=detector.detectBatch, args=[images, ])
    threads.append(thread)
    thread.start()
for thread in threads:
    thread.join()
duration = time.perf_counter() - ts
print("detectBatch()-multithread took:", duration*1000, "milliseconds")

PhuongNDVN avatar Nov 28 '22 07:11 PhuongNDVN