【问题标题】:Can DeepFace verify() accept an image array or PIL Image object?DeepFace verify() 可以接受图像数组或 PIL Image 对象吗?
【发布时间】:2021-06-06 07:27:31
【问题描述】:

我的 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 我只想知道是否有其他方法无需将图像保存到磁盘

【问题讨论】:

    标签: python image python-imaging-library verify


    【解决方案1】:

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

    这里,人脸对可以是精确的图像路径、numpy 数组或 base64 编码图像

    所以,大概,您可以将您的 PIL 图像 制作成这样的 Numpy 数组:

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

    【讨论】:

    • 非常感谢
    • 我做了 np.array(image_path),但我仍然收到错误 "raise ValueError("Face could not be detected ...." ) ,有什么建议吗?请帮助我,在此先感谢: )
    • @NadyrbekSultanov 你需要np.array(Image.open(image_path))
    • 但如果我想从 Image.fromarray() 获取图像?
    • @NadyrbekSultanov 您可以使用 2 个步骤。首先,您可以使用 im = Image.open(image_path) 获取 PIL Image 然后,其次,您可以使用 @987654325 从该 PIL Image 获取 Numpy 数组 @
    【解决方案2】:

    非常感谢兄弟,我按照你的方法得到了我的结果。

    对于其他人: 跟随兄弟 Mark Setchell 后,我再次遇到错误,但这正是因为我将一个输入作为路径传递,另一个作为 numpy 数组传递。 如果您必须传递 numpy 数组,请确保为两个输入参数传递它。

    picture= "extracted_face_picture/single_face_picture.jpg"
    picture= Image.open(picture)
    .
    .
    df.verify(picture, np.array(frame), "Facenet")
    

    更正:

    df.verify(np.array(picture),np.array(frame), "Facenet")
    

    非常感谢马克·塞切尔兄弟。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-10
      • 2016-01-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-12-10
      • 2019-12-31
      • 1970-01-01
      相关资源
      最近更新 更多