Skip to content

Doesn't IndexFaces return the UserId? (it's not..)

1

If I index several faces from the same person, create a User for it and Associate it with all of those faces.

Next time I index a new photo with that person, does the IndexFace return that same UserId for me on the response? On the docs it says it returns but doesn't elaborate furthern and in my case it's not returning. (https://docs.aws.amazon.com/rekognition/latest/APIReference/API_IndexFaces.html#API_IndexFaces_ResponseSyntax)

If it does not, why is there UserId on the IndexFaces response?

Thanks

asked a year ago91 views
1 Answer
0

Greeting

Hi Thiagosz!

Great question! Let’s unpack this together to clarify the behavior of IndexFaces and how it works with UserId. I can see where the documentation might leave some ambiguity, so let’s ensure you have a clear understanding of what's happening.


Clarifying the Issue

From your description, it seems like you’re indexing multiple faces for the same person, associating them with a UserId, and expecting that the IndexFaces operation will consistently return that same UserId when you index another photo of the same person. However, in your experience, IndexFaces is not returning the UserId in the response as you expected.

This behavior is understandable because IndexFaces primarily detects and stores unique face identifiers (FaceId) in the face collection. While Rekognition allows you to associate a UserId with faces through AssociateFaces, IndexFaces does not automatically return the UserId unless explicitly queried through operations like SearchFacesByUser. Let's break this down further and see how to achieve your intended workflow.


Why This Matters

When Rekognition doesn’t return the UserId in the IndexFaces response as expected, workflows relying on automated identification may falter. For example, if you're building a system to identify returning users in a loyalty program, failing to retrieve the UserId could lead to mismatched or unidentified accounts, frustrating customers and complicating your system. Understanding how Rekognition handles UserId ensures accurate face-user mapping, enabling a smoother and more reliable implementation.


Key Terms

  • IndexFaces: An operation that detects and stores metadata for faces in an image in a face collection. Returns FaceId and optionally other attributes.
  • UserId: A custom identifier associated with a user in Rekognition’s face collection, used with AssociateFaces and SearchFacesByUser.
  • Face Collection: A repository in Rekognition where face metadata is stored, indexed by unique FaceId.
  • SearchFacesByUser: An operation that retrieves face matches for a given UserId, returning associated faces and their metadata.

The Solution (Our Recipe)

Steps at a Glance:

  1. Use IndexFaces to detect and store face metadata in a face collection.
  2. Use AssociateFaces to associate FaceId values with a UserId.
  3. Use SearchFacesByUser to retrieve a match for an indexed face and its associated UserId.

Step-by-Step Guide:

  1. Index Faces in the Face Collection
    When you first index a face using the IndexFaces operation, Rekognition generates a FaceId and adds it to the specified face collection. This operation doesn't automatically associate the face with a UserId.
    import boto3
    
    rekognition = boto3.client('rekognition')
    
    response = rekognition.index_faces(
        CollectionId='MyFaceCollection',
        Image={'S3Object': {'Bucket': 'my-bucket', 'Name': 'my-image.jpg'}},
        ExternalImageId='OptionalTag',
        DetectionAttributes=['ALL']
    )
    
    for face in response['FaceRecords']:
        print(f"Indexed FaceId: {face['Face']['FaceId']}")

  1. Associate Indexed Faces with a UserId
    Once faces are indexed, use the AssociateFaces operation to link the indexed FaceId values to a UserId.

    response = rekognition.associate_faces(
        CollectionId='MyFaceCollection',
        UserId='User123',
        FaceIds=['face-id-1', 'face-id-2']
    )
    print(f"Associated Faces: {response['AssociatedFaces']}")
  2. Retrieve Matches for Future Photos
    When you index a new photo, use SearchFacesByUser to match the detected face to the UserId associated with it.

    response = rekognition.search_faces_by_user(
        CollectionId='MyFaceCollection',
        UserId='User123'
    )
    
    for match in response['FaceMatches']:
        print(f"Matched FaceId: {match['Face']['FaceId']} with Similarity: {match['Similarity']}")

    Use Case Example:
    In a loyalty program app for retailers, you might index faces of customers and associate them with a UserId. Without explicitly associating faces and querying with SearchFacesByUser, a returning customer might not be identified correctly, disrupting their experience. This method ensures seamless and accurate identification.


Closing Thoughts

The IndexFaces response includes the UserId field primarily for integrations where the indexed face is already associated with a UserId. However, this doesn’t happen automatically when new faces are indexed, as user associations must be manually managed. Instead, use SearchFacesByUser after association to retrieve the UserId when working with new photos.

For more information:


Farewell

I hope this clears up your questions, Thiagosz! Rekognition is a powerful tool, and understanding its mechanics ensures you're getting the most from it. If you have any follow-up questions or need further clarification, let me know—I’m happy to help! 😊


Cheers,

Aaron 😊

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.