Python Forum
AWS rekognition - index faces
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AWS rekognition - index faces
#1
Hi,

i am new in python trying to index faces using Rekogniton API's and getting the following error:

Error:
DetectionAttributes=[ 'ALL' ] File "C:\Program Files\Python37\lib\site-packages\botocore\client.py", line 312, in _api_call "%s() only accepts keyword arguments." % py_operation_name) TypeError: index_faces() only accepts keyword arguments.
here is the program:

import boto3  
import json

rek = boto3.client('rekognition') # Setup Rekognition  
s3 = boto3.resource('s3') # Setup S3  
print ("Getting Image")  

your_bucket = s3.Bucket('betaimagefolder1')

CollList = rek.list_collections()
print(CollList)

#response = rek.create_collection(CollectionId='TestYehuda')

for s3_file in your_bucket.objects.all():
   print(s3_file.key)
   image = s3.Object('betaimagefolder1',s3_file) # Get an Image from S3  
   #img_data = image.get()['Body'].read() # Read the image
   FaceRecord = rek.index_faces(
		image,
		CollectionId='TestYehuda',
	        ExternalImageId=None,
	        DetectionAttributes=[ 'ALL' ]
                )
   response1 = rekognition.search_faces_by_image(
	img_data,
        CollectionId='TestYehuda',
      	FaceMatchThreshold=threshold,
	)
   MatchRecord = response1['FaceMatches']
Thanks!!
Reply
#2
Please, post full traceback, not just the last line. Don't forget the error tags (I have added them for you in the first post)
try
FaceRecord = rek.index_faces(
        Image=image,
        CollectionId='TestYehuda',
            ExternalImageId=None,
            DetectionAttributes=[ 'ALL' ]
                )
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thanks its help! now i know how i should pass arg..
in last 4 hours i struggling to fix the next error.
can someone assist ?


Error:
Traceback (most recent call last): File "C:\Users\yehudada\PythonCC\rekognition_Distinct_face_1.py", line 23, in <module> DetectionAttributes=['ALL']) File "C:\Program Files\Python37\lib\site-packages\botocore\client.py", line 314, in _api_call return self._make_api_call(operation_name, kwargs) File "C:\Program Files\Python37\lib\site-packages\botocore\client.py", line 586, in _make_api_call api_params, operation_model, context=request_context) File "C:\Program Files\Python37\lib\site-packages\botocore\client.py", line 621, in _convert_to_request_dict api_params, operation_model) File "C:\Program Files\Python37\lib\site-packages\botocore\validate.py", line 291, in serialize_to_request raise ParamValidationError(report=report.generate_report()) botocore.exceptions.ParamValidationError: Parameter validation failed: Invalid type for parameter Image, value: s3.Object(bucket_name='betaimagefolder1', key=s3.ObjectSummary(bucket_name='betaimagefolder1', key='20[1].jpg')), type: <class 'boto3.resources.factory.s3.Object'>, valid types: <class 'dict'> Invalid type for parameter ExternalImageId, value: None, type: <class 'NoneType'>, valid types: <class 'str'>
import boto3  
import json

rek = boto3.client('rekognition') # Setup Rekognition  
s3 = boto3.resource('s3') # Setup S3  
print ("Getting Image")  

your_bucket = s3.Bucket('betaimagefolder1')

CollList = rek.list_collections()
print(CollList)

#response = rek.create_collection(CollectionId='TestYehuda')

for s3_file in your_bucket.objects.all():
   print(s3_file.key)
   image= s3.Object('betaimagefolder1',s3_file) # Get an Image from S3  
   #img_data = image.get()['Body'].read() # Read the image
   FaceRecord = rek.index_faces(
                CollectionId='TestYehuda',
		Image=image,
		ExternalImageId=None,
	        DetectionAttributes=['ALL'])
   response1 = rekognition.search_faces_by_image(
	image=image,
        CollectionId='TestYehuda',
      	FaceMatchThreshold=threshold,
	)
   MatchRecord = response1['FaceMatches']
   face = MatchRecord['Face']
   print ("Matched Face ({}%)".format(MatchRecord['Similarity']))
   print ("  FaceId : {}".format(face['FaceId']))
   print ("  ImageId : {}".format(face['ExternalImageId']))
	
Reply
#4
try
for s3_file in your_bucket.objects.all():
    image= {'S3Object':{'Bucket':bucket, 'Name':s3_file}}
    FaceRecord = rek.index_faces(CollectionId='TestYehuda', Image=image, DetectionAttributes=['ALL'])
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  detect Multiple faces using dlib vijaysagi 1 4,824 Jan-18-2017, 10:25 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020