pythonimagepython-imaging-libraryverify

Can DeepFace verify() accept an image array or PIL Image object?


My DeepFace Implementation

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

I am trying to pass a PIL Image instead of "*.jpg" to verify() function but it gives error

    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>)

I want to ask is there any way I can pass directly PIL Image object or image array without saving it to disk prior?

What I am passing:

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

Note that I can still successfully implement DeepFace with saving images in directories then reading them with imread() I only want to know if there are other ways without saving images to disk


Solution

  • If you are using this module, the documentation says:

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

    So, presumably, you can make your PIL Images into Numpy arrays like this:

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