Image recognition with customized notification using AWS
Hello Folks, this is a brief guide how to develop custom notification based model for Image Recognition using AWS functions as AWS Lambda, Rekognition, SNS, S3 bucket and other AWS services.
(If you are having AWS free tier account still you can perform this task)
Here are the main 4 steps we have to perform:
- Create an IAM ROLE with the full access of Rekognition + CloudWatch + S3 access.
- Create an SNS topic.
- Create S3 bucket.
- Create a Lambda Function.
The main functioning reasons of 4 steps.
- The Rekognition which is a API, will help us to recognize the object.
- AWS SNS is a simple notification based service which will Email us when image is being upload and image is been recognized.
- S3 bucket to store the images.
- Lambda function to create the logic of model.
Lets Get Started!
Create a role using Lambda as a service as it is the function where working will be done by setting the permissions as Full Access of S3, Cloudwatch and Rekognition. Create the role and you are done with the 1st step.
Create a Topic and name it according to the requirement and further click on Subscription to add your email-id on which you want to be notified on. Once you confirm your subscription then you are ready to go with the 3rd step.
Create a bucket and name it according to the requirement and click on next button to complete the process. We are ready to move to our main working step-
Click on Create Function, you will get 3 options and the most convenient to me was Blueprints as they are already configured and you can modify them according to your need. Search for Rekognition in search tab of Blueprints and you will have Rekognition-python. Choose the role we created earlier and similarly the S3 bucket created by us in step 3. You can add filter for accepting certain formats of image as .png, .jpg etc. Make sure to click on ENABLE the Lambda function. Click on create function and you have successfully built it.
We have to modify the code according to our requirements, here we only need LABELS so we can alter the python code. It is really important to understand the code and how it triggers the function. Here we have to couple of changes in code to run code smoothly.
Further upload the set of image to S3 bucket and you can get details by going to monitoring Tab as we have enabled the Cloudwatch, go to Logs for checking the Confidence value and name of Label.
The main work is to get notification on our device-
Go to Lambda function and dig in to the code area to instantiate BOTO3.CLIENT . Further for publishing the correct message add publish() function from SNS documentation. Alter the image filter string pattern and add ARN. Create a function and add label that sends message with only required variable as “Label” or “Confidence Level” as per the requirement. Now go back to S3 bucket and try uploading another set of image. You will receive an Email regarding the response.
Congratulations on learning something new!
Conclusion-
We created a function that recognizes image and we created a custom notification builder which will send us a notification when someone adds data for recognition followed by the results.