0

I have executed complete code..but not priting the last 'print statement'. Someone can help me out..I have uploaded all the pictures into AWS s3 bucket.

import boto3

s3_client = boto3.client('s3', aws_access_key_id='xxxxxxxxxxxxx',
                               aws_secret_access_key='xxxxxxxxxxxxxxxxx',)
collectionId='xxxxxxxxx' #collection name

rek_client=boto3.client('rekognition', aws_access_key_id='xxxxxxxxxx',
aws_secret_access_key='xxxxxxxxxxxxxxx',)

bucket = 'xxxxxxxxxxx' #S3 bucket name
all_objects = s3_client.list_objects(Bucket =bucket )
for content in all_objects['Contents']:
   collection_name, sep, collection_image =content['Key'].parition('/')
   label = collection_name
   print('indexing: ',label)
   if collection_image:
      image = content['Key']
      index_response=rek_client.index_faces(CollectionId=collectionId,
                            Image={'S3Object': 'Bucket':bucket,'Name':image}},
                            ExternalImageId=label,
                            MaxFaces=1,
                            QualityFilter="AUTO", DetectionAttributes=['ALL'])
      print('FaceId: ',index_response['FaceRecords'][0]['Face']['FaceId'])
  • I am deleting this post and edited other one in detail. Sorry for inconvinence. – user11649630 Sep 05 '19 at 11:38
  • No problem! The other one is closed so you might as well keep this version I guess? But same questions: can you put a print line before the index_faces call to make sure it's being executed? Can you add a line immediately after it, at the same scope, to dump out the index_response e.g. [with pprint](https://stackoverflow.com/a/193539/243245)? Do you need to indent the `collection_name, sep, ...` line so that it's inside the for? (Python is whitespace sensitive). Can you add a print after that line to show what it parsed the line into? And before to show the line before it's parsed? etc. – Rup Sep 05 '19 at 11:40
  • I have done what you have said..but got below error..botocore.errorfactory.InvalidS3ObjectException: An error occurred (InvalidS3ObjectException) when calling the IndexFaces operation: Unable to get object metadata from S3. Check object key, region and/or access permissions. – user11649630 Sep 05 '19 at 11:52
  • Great, that's something to try and solve. I'd guess it's saying the access key you've passed to the rekognition call does not have permission to read your S3 bucket. Is that likely? Is it the same key? Can you use that key for the list_objects call successfully? – Rup Sep 05 '19 at 11:54
  • Its indexing first 2 images then again generating error: C:/Users/tg/PycharmProjects/Face_Rekog_Practice/Indexing_Faces.py indexing: AK indexing: AK Traceback (most recent call last): File "C:/Users/tg/PycharmProjects/Face_Rekog_Practice/Indexing_Faces.py", line 28, in DetectionAttributes=['ALL']) – user11649630 Sep 05 '19 at 11:56
  • I don't see the error message there. If it's a long stack trace you can edit it into the question. But hopefully the actual error message is more obvious. Is it that it doesn't like `DetectionAttributes=['ALL']`? – Rup Sep 05 '19 at 12:00
  • Thank you for your help..it indexing all the pictures ..but not printing the last print statement...!! – indexing: BB-2Faces.jpg indexing: BB-Angaga.jpg indexing: BB-Test.jpg indexing: Brani.jpg Process finished with exit code 0 – user11649630 Sep 05 '19 at 12:06
  • Again that might be an indent problem. It needs to be indented underneath the `index_response=rek_client.index_faces` line to be executed inside the loop with the same scope. But it ought to execute for the last face or give you an error I'd have thought. – Rup Sep 05 '19 at 12:06
  • I have gave different indents but..its not displaying the ouptput of last print statement..I have uploaded all pictures together in s3 bucket. – user11649630 Sep 05 '19 at 12:12
  • Can I add one more post with specific error ? or else Can i edit/delete this post and add newone ? Please let me know – user11649630 Sep 05 '19 at 12:18
  • I thought you said you weren't getting any errors now, it's just not running the last print statement? You might as well edit the error into this question for now. – Rup Sep 05 '19 at 12:19
  • @user11649630 The best thing to do is to edit the current one by clicking on "edit". Too many post deletions are frowned upon by SO. – glglgl Sep 05 '19 at 12:24
  • I have edited the post with exact problem..Thank you so much. – user11649630 Sep 05 '19 at 12:25
  • Finally i am able to Execute the code successfully in pycharm..!! But the same code not working in Raspberrpi OS..!! – user11649630 Sep 05 '19 at 14:22

0 Answers0