gpt4 book ai didi

python - DeepFace verify() 可以接受图像数组或 PIL Image 对象吗?

转载 作者:行者123 更新时间:2023-12-02 02:09:57 27 4
gpt4 key购买 nike

我的 DeepFace 实现

def verify(img, frame, model):
results= DeepFace.verify(img, frame, enforce_detection=False, model_name=model)
print("result: ", results)
verification= results['verified']
if verification is True:
print(model, "Successfully recognised. SCORE=")
return
return

我试图将 PIL 图像而不是“*.jpg”传递给 verify() 函数,但它给出错误

    raise ValueError("Invalid arguments passed to verify function: ", instance)
ValueError: ('Invalid arguments passed to verify function: ', <PIL.Image.Image image mode=RGB size=160x160 at 0x7F4D5D03FBE0>)

我想问有什么办法可以直接传递PIL Image对象或图像数组而不需要事先将其保存到磁盘吗?

我正在传递什么:

picture= "extracted_face_picture/single_face_picture.jpg"
picture= Image.open(picture)
picture= picture.resize((160,160))

frames_from_npz= "video_faces.npz"
frames= np.load(frames_from_npz)
frames= frames["arr_0"]
i=0
for frames_arr in frames:
frame= Image.fromarray(frames_arr)

df.verify(picture,frame, "Facenet")
print(i, "Above reuslts are for frame", frame_num)

i+= 1

请注意,我仍然可以通过将图像保存在目录中然后使用 imread() 读取它们来成功实现 DeepFace,我只想知道是否还有其他方法而不将图像保存到磁盘

最佳答案

如果您使用this模块,文档说:

Herein, face pairs could be exact image paths, numpy array or base64 encoded images

因此,大概您可以将 PIL 图像 放入 Numpy 数组中,如下所示:

results = DeepFace.verify(np.array(PILIMAGE), ...)

关于python - DeepFace verify() 可以接受图像数组或 PIL Image 对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67856738/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com