[英]How to decode image roi with tensor flow?
在使用 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/generation/adversarial_fgsm謝謝。
tf.image.decode_image
用於將原始輸入字節解碼為張量,這里不是這種情況。
我想您想要的是將 numpy 數組( roi
)轉換為tf.Tensor
。 為此,您可以使用tf.convert_to_tensor
https://www.tensorflow.org/api_docs/python/tf/convert_to_tensor
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.