face_recognition icon indicating copy to clipboard operation
face_recognition copied to clipboard

how to get accuration from the processing?

Open MR-michaelrio opened this issue 1 year ago • 2 comments

  • face_recognition version:
  • Python version: 3
  • Operating System: windows

Description

i want to get a accuation from the face recognition processing but i cant find where the code for get a accuration in your examples

What I Did

@app.post("/face_recognition") async def recognize_faces(file: UploadFile = File(...)): # Save the uploaded file temporarily file_location = f"temp/{file.filename}" with open(file_location, "wb") as buffer: buffer.write(await file.read())

# Load the image file and find face locations and encodings
image = face_recognition.load_image_file(file_location)
face_locations = face_recognition.face_locations(image)
face_encodings = face_recognition.face_encodings(image, face_locations)

# Load saved encodings
encodings = []
for filename in os.listdir("encodings"):
    if filename.endswith(".txt"):
        with open(os.path.join("encodings", filename), "r") as f:
            name = os.path.splitext(filename)[0]
            lines = f.readlines()
            encoding = [float(x) for x in lines[0].strip().split()]
            encodings.append((name, encoding))

# Find matches
matches = []
for encoding in face_encodings:
    for name, saved_encoding in encodings:
        match = face_recognition.compare_faces([saved_encoding], encoding)
        if match[0]:
            matches.append(name)
            os.remove(file_location)
            return {"matches": matches,"face": "Recognize"}
        
# Remove the temporary file
os.remove(file_location)
return {"face": "NoRecognize"}

MR-michaelrio avatar May 23 '23 05:05 MR-michaelrio

Hi, do you mean that you need the probability at which the face recognition model is recognizing the face? Because there is no such thing as accuracy while recognizing faces, It is the probability at which the model is recognizing the faces. Accuracy will be how many times it recognized faces correctly. Please clarify this, so that I can help furhter.

Thank You

Devang-C avatar Jun 22 '23 11:06 Devang-C

if you want to get the number of similiarity between two images, you can using face_distance function

maika-kanaka avatar Dec 06 '23 16:12 maika-kanaka