我的函数本身工作正常,但当我作为辅助角色运行它时则不然



我正在尝试在Python中并行运行多个Yolos。

有一个函数,我正在尝试将其用作辅助角色。 像这样:

import darknet as dn
def yolo(input_queue, net, meta):
    while True:
        task = input_queue.get_nowait()
        c = task.shape[0]
        h = task.shape[1]
        w = task.shape[2]
        task = (task/255.0)
        task = task.flatten()
        new_arr = np.copy(task).astype(np.float32) 
        new_arr = np.ctypeslib.as_ctypes(new_arr)
        im = dn.IMAGE(w,h,c,new_arr)
        dn.rgbgr_image(im)
        print(dn.detect(net, meta, im))

你可以在这里找到暗网文件。

我们不要谈论我将数组转换为 ctype 数组的方式。 这里已经讨论过了。

如果我将此功能作为普通函数运行,则就像一个魅力。但是,如果我像这样以工人身份运行它:

p = Process(target=yolo, args=(input_queue, net, meta))
p.start()

它一直到最后一行,然后给我这个错误:

CUDA Error: initialization error
python: ./src/cuda.c:36: check_error: Assertion `0' failed.

我无法弄清楚为什么会发生此错误。谁能帮忙? 导致此问题的这两种使用此函数的方式之间有什么区别?

多亏了这一点,我发现问题是您无法在具有不同 PID 的进程之间共享 CUDA 中的上下文,这是有意义的。所以我发现,如果我在同一过程中运行相关的东西(在我的情况下,net),那么它可以正常工作。在此之前,我在开始工作之前装载重量。

最新更新