serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://www.youtube.com/watch?v=WnUVYQP4h44&list=PLsS_1RYmYQQFdWqxQggXHynP1rqaYXv_E&index=1
MIT License
14.31k stars 2.2k forks source link

DeepFace.verify is giving me different distance values for same settings #288

Closed fizamurtaza closed 3 years ago

fizamurtaza commented 3 years ago

Hello, Why I am getting different results every time I run with same input images and same settings?

fizamurtaza commented 3 years ago

image

serengil commented 3 years ago

That's very interesting. Which version of deepface you are using? What is the exact content of untitled0.py?

The following file exists in your environment? HOME_FOLDER/.deepface/weights/facenet_weights.h5

fizamurtaza commented 3 years ago

-- coding: utf-8 --

here is the code: """ from IPython import get_ipython def reset(): get_ipython().magic('reset -sf')

calling the dependencies

from deepface import DeepFace import cv2 import matplotlib.pyplot as plt plt.close('all')

importing the images

datapath = 'D:/Fiza_Murtaza/codes/deepface-master/tests/dataset' img1_path = datapath + "\Img68.jpeg" img2_path = datapath + '\Img69.jpeg'

confirming the path of images

img1 = cv2.imread(img1_path) img2 = cv2.imread(img2_path)

plt.imshow(img1[:, :, ::-1 ]) #setting value as -1 to maintain saturation

plt.show()

plt.imshow(img2[:, :, ::-1 ])

plt.show()

model1 = DeepFace.build_model('VGG-Face') models = ["VGG-Face", "Facenet", "Facenet512", "OpenFace", "DeepFace", "DeepID", "ArcFace", "Dlib"] result = DeepFace.verify(img1_path, img2_path, model_name = models[1], model=model1) print(result)

fizamurtaza commented 3 years ago

yes weights exist in the environment. I believe that I am passing my own image but these are in .jpeg extension. Whenever I try to very .jpeg images it gives me different results (verification and distance) but when I use .jpg images results are same on each run.

fizamurtaza commented 3 years ago

How to train the model on new images?

serengil commented 3 years ago

Could you share your .jpeg images. I need to re-create the conditions you have.

what was your tensorflow version btw?

serengil commented 3 years ago

when I tested verify function with .jpeg extension images, distance seems always same.

obj = DeepFace.verify("1.jpeg", "2.jpeg", model_name = 'Facenet')

this returns the following response

{'verified': False, 'distance': 1.036256273901735, 'max_threshold_to_verify': 0.4, 'model': 'Facenet', 'similarity_metric': 'cosine'}

it seems that your environment causes that trouble. If you share your image pair, I can test it. I'm closing this issue because it is an environmental issue.

1 2

fizamurtaza commented 3 years ago

thank you @serengil. I think it is the environment issue because when I tried the above two jpeg images (which you provided) i am facing same issue of different results whenever I run the code. How I can resolve the environment issue?

serengil commented 3 years ago

what was your deepface and tensorflow versions?

fizamurtaza commented 3 years ago

Thank you @serengil deepface = 0.0.65 tensorflow = 2.5.0

serengil commented 3 years ago

you are using the latest deepface.

could you downgrade your tf to 2.2.0?

fizamurtaza commented 3 years ago

ok let me do that.

fizamurtaza commented 3 years ago

I have downgraded tf to 2.2.0 and the problem is still same.

serengil commented 3 years ago

what about python version? I'm using python 3.8.3.

fizamurtaza commented 3 years ago

I am using 3.8.10

serengil commented 3 years ago

I re-open this issue because I don't know what to do. However, some people might face with this trouble and help us.

serengil commented 3 years ago

Could you delete this file: HOME_FOLDER/.deepface/weights/facenet_weights.h5

Let deepface to install the facenet weights again. BTW, you are still using facenet in your experiments?

fizamurtaza commented 3 years ago

yes thank you @serengil

I feel this is issue is with only .jpeg images not on .jpg images.

fizamurtaza commented 3 years ago

yes I am using facenet

serengil commented 3 years ago

what if deepface enforce you working with just jpg images?

fizamurtaza commented 3 years ago

yes this is the only solution I think I will use .jpg images now

what if deepface enforce you working with just jpg images?

serengil commented 3 years ago

closing this because of inactivity