/amazon-ipc-ai-saas

Primary LanguagePythonApache License 2.0Apache-2.0

中文

Intelligent IP Camera With AI SaaS Solution

Contents

Introduction

This solution aims to empower IP camera industry with artificial intelligence (AI) functionalities based on Amazon Web Services. It provides face detection, human body detection and face comparison based on Amazon S3, Lambda, API Gateway, Sagemaker services. The AI algorithms are packaged in ECS container, which has the advantage of easy to expand and pluggable. This solution is an end-to-end SaaS application, and all inference are stored in S3 bucket, which could be further used to retrain the model and help customers to improve algorithms' performance with incremental data in real product environment.

Currently this solution support 3 major functions:

  • Face Detection
  • Human Body Detection
  • Face Comparison

Architecture

IPC_AI_SaaS_Architecture

The effect of services illustrated in architecture could be detailed as below:

  1. Amazon API Gateway: it routes user's request, which includes the request image's base64 encoded sequence.
  2. Amazon Lambda Function: lambda function is responsible for invoke the sagemaker endpoint to infer the response and meanwhile, it stores request image and inference result into S3 bucket.
  3. Amazon S3 Bucket: it is used to store the input image and corresponding result of each API request.
  4. Sagemaker Endpoint + Load Balancing + ML Instances: the sagemaker endpoint is responsible for processing users' request, i.e., face detection/human body detection/face comparison are all implemented in Sagemaker endpoint, user can integrate autoscaling to control the hosting machines' amount based on work load。

Deployment

Things to Know

  • This solution will automatically provision Amazon S3 bucket, API Gateway, Lambda Function, Sagemaker Model/Configuration/Endpoint resources in your deploy account.
  • The whole deployment process will take 10-20 minutes。

Configuration Parameters

When deploy this solution,user need to specify 5 parameters: applicationTypedeployInstanceTypedetectorModelNamefaceDetectAndCompareModelNamesaveRequestEvents, which is introduced in detail in Table below:

Parameter Name Default Value Description
applicationType face-detection specify the service type of this solution,the value should be one of face-detectionbody-detectionface-comparison
deployInstanceType ml.g4dn.xlarge specify the machine of hosting inference service,the value should be one of ml.m5.xlarge, ml.g4dn.xlarge
detectorModelName yolo3_darknet53_coco specify the detector name of face detection or human body detection,it is worth to mentioning that it is only valid when applicationType is configured as face-detection or body-detection, the detector name should be one of ssd_512_resnet50_v1_coco, yolo3_darknet53_coco, yolo3_mobilenet1.0_coco, faster_rcnn_fpn_resnet101_v1d_coco
faceDetectAndCompareModelName retinaface_mnet025_v2+MobileFaceNet specify face detection model and representation model for face comparison scenario,it is valid when applicationType is configured as face-comparison, the value should be one of retinaface_mnet025_v2+LResNet100E-IR, retinaface_mnet025_v2+MobileFaceNet, retinaface_r50_v1+MobileFaceNet
saveRequestEvents No boolean flag which indicates to store all inference events (input image and return response) into S3 bucket,the value should be one of Yes, No

Deploy via Cloudformation

Please follow below steps to deploy this solution via AWS Cloudformation.

  1. Sign in to AWS Management Console, switch to the region to deploy the CloudFormation Stack to.

  2. Click the following button to launch the CloudFormation Stack in that region.

    • For China Partition (cn-north-1, cn-northwest-1)

    Launch Stack

    • For Standard Partition (us-east-1, us-west-2)

    Launch Stack

  3. Click Next. Change the stack name if required.

  4. Click Next. Configure additional stack options such as tags (Optional).

  5. Click Next. Review and confirm acknowledgement, then click Create Stack to start the deployment.

Note: You can simply delete the stack from CloudFormation console if this solution is no longer required.

Deploy via CDK

If you want to use AWS CDK to deploy this solution, please make sure you have met below prerequisites:

  • AWS Command Line Interface
  • Node.js 12.x or later Under the project source folder, run below to compile TypeScript into JavaScript.
cd source
npm install -g aws-cdk
npm install && npm run build

Then you can run cdk deploy command to deploy the solution. Please specify the parameter value if needed, for example:

cdk deploy \
--parameters applicationType=face-detection \
--parameters deployInstanceType=ml.g4dn.xlarge \
--parameters detectorModelName=yolo3_darknet53_coco \
--parameters faceDetectAndCompareModelName=retinaface_mnet025_v2+MobileFaceNet \
--parameters saveRequestEvents=Yes

Note: You can simply run cdk destroy if the solution task is no longer required. This command will remove the stack created by this solution from your AWS account.

Security

See CONTRIBUTING for more information.

License

See the LICENSE file for our project's licensing. We will ask you to confirm the licensing of your contribution.