python - 如何使用张量流解码图像 roi?
问题描述
在使用 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
推荐阅读
- java - 如何使用 Stream API 按日期对列表进行分组以映射?
- php - JSON POST Empty 使用 cURL 命令
- javascript - 使用正则表达式查找对象的值
- bash - 在保留行组的同时拆分文件
- coq - 如何在 Coq 中重写给定的两个依赖类型相等
- git - git 是否有一个命令可以将工作树重置为 HEAD 但保留索引的分阶段更改?
- dictionary - 将值插入地图时出现恐慌/错误
- virtual-machine - Virtualbox 没有端口转发端口 8080 但其他端口都可以
- kubernetes - 使用一个 API 请求从节点中删除特定的污点
- excel - MS Access VBA 正在创建多个报告电子邮件,并且参数未存储表单中的引用