I am working on a project that needs to use YOLOv7 for object detection. I used the detect() function as given on the original source code and modified a little bit just to make it as a function (originally the detect() function can not be imported and run). However I have not changed the core library modules as given in the utils and models folders. Then I imported modified detect() into another module for parallel processing with other modules. And also I have used queue to share the detection data into the someModulesWork() function.

The original code : https://github.com/WongKinYiu/yolov7

The code I used for multiprocessing:

from yolov7 import detect
import some_module
from multiprocessing import Process, Queue

# Another module for multiprocessing
def someModulesWork(q):
    s = q.get()
    # do something

if __name__ == "__main__":
    q = Queue()

    ### Just to test if its really working or not and it works independently without multiprocessing ###
    # detect(img, 'yolov7-tiny.pt', 0.25, 0.45, 640, 0)
    #
    # print(detections)

    # creating new processes
    p1 = Process(target=detect, args=(q, img, 'yolov7-tiny.pt', 0.25, 0.45, 640, 0))
    p2 = Process(target=someModulesWork, args=(q,))

    #running process p1 and p2
    p1.start()
    p2.start()

But as soon as I run the code, the YOLOv7 stops detecting other objects and only detects one person. But whenever I run the same imported YOLOv7 independently without using python's multiprocessing library, it detects all the objects in the image. So I guessed it might be creating problem because of using multiprocessing in the code or in the YOLOv7 library the codes are somehow in parallelism and I am creating collision by using it again somehow. Is that how it works??

1

There are 1 best solutions below

1
On

you should try torch multiprocessing its fully on GPU.