In this module we will build an end to end solution to recognize public figures in images and videos.
This module requires completion of previous modules:
- Go to S3 in AWS Console at https://s3.console.aws.amazon.com/s3/
- Click on Create bucket
- Under Name and region:
- Bucket name: Enter a bucket name
- Choose same region you used for earlier two modules
- Click Next.
- Leave default values for following steps and on last screen click Create bucket
- Go to Lambda in AWS Console at https://console.aws.amazon.com/lambda/
- Click on Create function.
- Under Create function, Author from scratch should be selected as default
- Under Author from scratch:
- Name: reinvent-video-analysis
- Runtime: Python 3.6
- Role: Choose and existing role
- Existing role: celebrity-recognition-LambdaRole-xxxxxxxxx
- Click Create function
- Copy code from lambda-video-analysis.py and replace code under Function code
- Set timeout to 15 minutes. and click save
- Under Add triggers, select S3
- Under Configure triggers:
- Bucket: Select the S3 bucket you just created in earlier step
- Event type: Leave default Object Created (All)
- Leave defaults for Prefix and Suffix and make sure Enable trigger checkbox is checked
- Click Add.
- Click Save on the top right to save changed to Lambda function
- Download media.mp4
- Go to S3 in AWS Console at https://s3.console.aws.amazon.com/s3/
- Go to S3 bucket you created earlier, and upload media.mp4 you just downloaded
- This will trigger lambda function and you should see a JSON file will appear in the bucket in few minutes.
- You can continue to next step and in few minutes refresh your S3 bucket to make sure you get the JSON file.
- Go to Lambda in AWS Console at https://console.aws.amazon.com/lambda/
- Click on Create function.
- Under Create function, Author from scratch should be selected as default
- Under Author from scratch:
- Name: reinvent-celebrity-recognition
- Runtime: Python 3.6
- Role: Choose and existing role
- Existing role: celebrity-recognition-LambdaRole-xxxxxxxxx
- Click Create function
- Under Environment variables, add a variable:
- Key: s3_bucket
- Value: Name of S3 bucket you created earlier
- Under Basic settings:
- Set Timeout to 10 seconds
- Download lambda-celebrity-recognition.zip
- Under Function code:
- Code entry type: Upload a zip file
- Under Function package, click Upload and select the zip file you downloaded in earlier step
- Click Save.
- Click on dropdown next to Test, and click on Configure test events
- For Event name: apigateway
- Replace sample JSON with JSON from lambda-test-event.json
- Click Create
- Click Test. If everything is setup correctly, you should see a response with recognized celebrity name.
-
Go to API Gateway in AWS Console at https://console.aws.amazon.com/apigateway/
-
Click on Get Started (if this is first time in API GW Console) or Click on Create API
-
Select Import from Swagger or Open API 3
-
Copy code from apigateway.yaml and paste it in the text box
-
For EndPoint Type: Select Edge Optimized and click Import.
-
Under /GetCelebrityRecognition:
- Click on GET
- Click on Integration Request
- Update Lambda Region to your region (if needed). Make sure to click on small check icon to save the selected value
- Lambda Function: Click on edit icon, and start typing name of your lambda function "reinvent-celebrity-recognition". As it appears in the list, select the lambda function.
- Click on small check icon to save the selected value
- Click OK on the prompt to add permission to Lambda function.
-
Under /RecognizeCelebrities
- Click POST
- Click on Integration Request
- Update Lambda Region to your region (if needed). Make sure to click on small check icon to save the selected value
- Lambda Function: Click on edit icon, and start typing name of your lambda function "reinvent-celebrity-recognition". As it appears in the list, select the lambda function.
- Click on small check icon to save the selected value
- Click OK on the prompt to add permission to Lambda function.
-
Under reinvent-celebrity-recognition
- Click ANY
- Click on Integration Request
- Update Lambda Region to your region (if needed). Make sure to click on small check icon to save the selected value
- Lambda Function: Click on edit icon, and start typing name of your lambda function "reinvent-celebrity-recognition". As it appears in the list, select the lambda function.
- Click on small check icon to save the selected value
- Click OK on the prompt to add permission to Lambda function
-
Click on Action, and then Deploy API.
-
Click on dropdown for Deployment stage and click New Stage
-
For Stage name: Enter prod and click Deploy.
-
Make note of Invoke URL as you will need this in later step
- Download whoswho.html.
- At line 89, update apiGatewayBaseUrl with invoke URL of your API Gateway endpoint you noted in earlier step. Example: https://XXXXXX.execute-api.us-east-2.amazonaws.com/prod
- Upload modified whoswho.html to your S3 bucket where you uploaded media.mp4 in earlier step
- Make both whoswho.html and media.mp4 public so you can view web app in the browser.
- From S3 bucket, click on whoswho.html to view it in browser
- You should see recognized celebrities along with their timeline in the left pane.
- While video is playing, you should see celebrity arrival timeline above the video.
- Anytime while video is playing, click on Recognize Celebrity button to recognize celebrities in the frame.