Skip to content

Can we move face id and user to another collection in AWS Rekognition?

0

I have many collections, and each collection has many user and face IDs. I wanna move user to another collection. So, is it possible to move the user and face id to another collection?

asked 2 years ago250 views

1 Answer
0

Yes, it is possible to move a user and their associated face IDs from one collection to another in Amazon Rekognition. Here are the steps to do it:

  1. Retrieve the user and face IDs from the current collection:

    • Use the ListFaces operation to retrieve the list of faces associated with the user you want to move.
    • Note down the UserId and FaceId for each face belonging to that user.
  2. Delete the user and faces from the current collection:

    • Use the DeleteUser operation to delete the user from the current collection.
    • Use the DeleteFaces operation to delete the faces associated with the user from the current collection.
  3. Add the user and faces to the new collection:

    • Use the CreateUser operation to create the user in the new collection.
    • Use the AddFaces operation to add the faces associated with the user to the new collection.

Here's some sample code in Python to demonstrate the process:

import boto3

# Create Rekognition client
rekognition = boto3.client('rekognition')

# Current collection
current_collection_id = 'current-collection'

# New collection
new_collection_id = 'new-collection'

# User to move
user_id = 'user-to-move'

# Step 1: Retrieve the user and face IDs from the current collection
response = rekognition.list_faces(CollectionId=current_collection_id, UserIDs=[user_id])
faces = response['Faces']
face_ids = [face['FaceId'] for face in faces]

# Step 2: Delete the user and faces from the current collection
rekognition.delete_user(CollectionId=current_collection_id, UserId=user_id)
rekognition.delete_faces(CollectionId=current_collection_id, FaceIds=face_ids)

# Step 3: Add the user and faces to the new collection
rekognition.create_user(CollectionId=new_collection_id, UserId=user_id)
for face_id in face_ids:
    rekognition.add_faces_to_collection(CollectionId=new_collection_id, UserId=user_id, ExternalImageId='face-image', FaceId=face_id)

This code retrieves the user and face IDs from the current collection, deletes the user and faces from the current collection, and then creates the user and adds the faces to the new collection.

Make sure to replace the current_collection_id, new_collection_id, and user_id with the appropriate values for your use case.

By following this process, you can move a user and their associated face IDs from one collection to another in Amazon Rekognition.

answered 2 years ago

EXPERT

reviewed 2 years ago

  • in boto3.client('rekognition'), there is no add_faces_to_collection function.

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.