缓冲区dtype在numba中不能作为缓冲区。

问题描述 投票:0回答:1

我试图将我写的一个双边滤波器通过numba转换到我的GPU上运行,但我似乎不能让它工作!我得到的错误是:我的GPU在运行时出现了错误。我得到的错误信息是

TypeError: Buffer dtype cannot be buffer, have dtype: array(float64, 2d, A)

从下面的代码中。

 @vectorize([(float64[:,:], float64[:,:])], target='cuda')
def apply_filter(img, filteredImage):

    imh, imw = img.shape[:2]
    hd = int((diameter - 1) / 2)

    for h in range(hd, imh - hd):
        for w in range(hd, imw - hd):
            Wp = 0
            filteredPixel = 0
            radius = diameter // 2
            for x in range(0, diameter):
                for y in range(0, diameter):

                    currentX = w - (radius - x)
                    cureentY = h - (radius - y)

                    intensityDifferent = img[currentX][cureentY] - img[w][h]
                    intensity = (1.0/ (2 * math.pi * (sIntesity ** 2))* math.exp(-(intensityDifferent ** 2) / (2 * sIntesity ** 2)))
                    foo = (currentX - w) ** 2 + (cureentY - h) ** 2
                    distance = cmath.sqrt(foo)
                    smoothing = (1.0 / (2 * math.pi * (sSpace ** 2))) * math.exp( -(distance.real ** 2) / (2 * sSpace ** 2))
                    weight = intensity * smoothing
                    filteredPixel += img[currentX][cureentY] * weight
                    Wp += weight

            filteredImage[h][w] = int(round(filteredPixel / Wp))


if __name__ == "__main__":
    src = cv2.imread("messy2.png", cv2.IMREAD_GRAYSCALE)
    src = src.astype(np.float64)
    filtered_image_own = np.zeros(src.shape)
    apply_filter(src, filtered_image_own)
    filtered_image_own = filtered_image_own.astype(np.uint8) 
    cv2.imwrite("filtered_image4.png", filtered_image_own)

我找了一圈,除了发现这个错误可能是因为传入了一个列表外,没有发现任何无用的东西?但是我的两个参数都是二维数组,签名应该是正确的。为什么我得到这个错误?

python numpy cuda numba
1个回答
1
投票

要传入数组或接收数组输出,最好使用 guvectorize(). 查看一下 Numba docs本博客 以了解详细的使用情况。

© www.soinside.com 2019 - 2024. All rights reserved.