ageitgey / face_recognition

The world's simplest facial recognition api for Python and the command line
MIT License
53.38k stars 13.48k forks source link

how to get accuration from the processing? #1508

Open MR-michaelrio opened 1 year ago

MR-michaelrio commented 1 year ago

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"}
Devang-C commented 1 year ago

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

maika-kanaka commented 11 months ago

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