【问题标题】:How to decode image roi with tensor flow?如何使用 tensorflow 解码图像 roi?
【发布时间】:2020-09-13 03:23:53
【问题描述】:

在使用 haarcasde 文件检测后从面部检测到图像后。 但是我收到了这个错误

/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_string_ops.py in substr(input, pos, len, unit, name)
   1888       _result = pywrap_tfe.TFE_Py_FastPathExecute(
   1889         _ctx._context_handle, tld.device_name, "Substr", name,
-> 1890         tld.op_callbacks, input, pos, len, "unit", unit)
   1891       return _result
   1892     except _core._FallbackException:

ValueError: Failed to convert a NumPy array to a Tensor (Unsupported object type int).

这是我的代码

def detect_and_noise_face(img):

    # Watch solutions video for line by line explanation!

    face_img = img.copy()
    roi = img.copy()

    face_rects = face_cascade.detectMultiScale(face_img,scaleFactor=1.3, minNeighbors=3) 
    for (x,y,w,h) in face_rects: 

        roi = roi[y:y+h,x:x+w]
        image = tf.image.decode_image(roi)

    return face_img

我为什么要解码图像,因为我试图在该 roi 上创建对抗性示例。 https://www.tensorflow.org/tutorials/generative/adversarial_fgsm 谢谢。

【问题讨论】:

    标签: python numpy opencv tensorflow


    【解决方案1】:

    tf.image.decode_image 用于将原始输入字节解码为张量,此处并非如此。

    我猜你想要的是将 numpy 数组 (roi) 转换为 tf.Tensor。为此,您可以使用 tf.convert_to_tensor https://www.tensorflow.org/api_docs/python/tf/convert_to_tensor

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-16
      • 2017-06-18
      • 2017-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多