如何将“cv2.magnitude”转换为张量流

时间:2021-02-24 08:05:48

标签: python tensorflow gradient sobel

img = tf.image.rgb_to_grayscale(input)
sobel = tf.image.sobel_edges(img)
dx = np.asarray(sobel[0, :, :, :, 0])  # Sobel_X
dy = np.asarray(sobel[0, :, :, :, 1])  # Sobel_Y
dx = tf.cast(dx, tf.uint8)
dy = tf.cast(dy, tf.uint8)
mag = cv2.magnitude(dx, dy)  # gradient magnitude , no channel#### error 

我不知道如何将 opencv 函数 mag = cv2.magnitude(dx, dy) 转换为 tensorflow

还有一个问题,tensorflow中是否有sobel_x、sobel_y函数

错误信息

File "/home/semi/PycharmProjects/ReflectionDecomposition2/main.py", line 563, in <module> network = build(input) File "/home/semi/PycharmProjects/ReflectionDecomposition2/main.py", line 422, in build mag = cv2.magnitude(dx, dy) # gradient magnitude , no channel#### error TypeError: x data type = 17 is not supported

我使用的是 ubuntu18.04、python 3.6、cuda 10.0、cudnn 7.4、Tensorflow 1.14

那是 TF 1.14.0 API 我找不到 sobel 和梯度大小,因为旧版本很难找到

TF 1.14.0 API:https://github.com/tensorflow/docs/tree/r1.14/site/en/api_docs/python/tf

我无法升级到 TF2.0,我正在使用 github 代码

cv2.magnitude 是梯度的大小

0 个答案:

没有答案