Quickly build Serverless face recognition offline service

Introduction to the

First, a few important concepts emerge from this article:

Function Compute: Function Compute is an event-driven service that lets the user write code and upload it instead of managing the server. Function computing prepares computing resources and runs user code on an elastic scale, with users paying only for the resources consumed by the actual code running. Function workflow: A Function workflow is a fully managed cloud service that coordinates the execution of multiple distributed tasks. Users can arrange distributed tasks in order, branch, parallel, etc. FnF will reliably coordinate task execution according to the set steps, track the state transitions of each task, and execute user-defined retry logic when necessary to ensure smooth workflow completion. Function workflow for more information
This article will focus on how to quickly deploy a service to batch process picture files offline and label faces through functional computation and functional workflow.

Open the service

  1. Free open function calculation, pay by volume, function calculation has a large free amount.
  2. Function workflow is opened for free and paid by volume. At present, the product is in the public testing stage and can be used for free.
  3. Open object storage for free and pay by volume.
The solution





The process is as follows:

  1. Set timing trigger, timing trigger function calculation function.
  2. Once the function is triggered, the process in the function workflow is invoked.
  3. The process in the function workflow is executed:
  4. Call the function in the calculation to list the image files in the root path of the OSS Bucket.
  5. For the file list listed in Step 1, for each file:
  • Call function calculation in the function processing, face recognition and annotation. Annotated files are stored in OSS, and processed files are finally transferred.


  1. Check whether there are more files under the current OSS root path
  • If so, proceed to Step 1
  • If no, end the process




Quick start

  1. Clone project to local


  1. Replace project directory template. Yml file YOUR_BUCKET_NAME for OSS Bucket in the hangzhou area (can not hangzhou area, need to be synchronized to modify OSS_ENDPOINT) ROSTemplateFormatVersion: ‘2015-09-01’ Transform: ‘Aliyun::Serverless-2018-04-03’ Resources: face-recognition: Type: ‘Aliyun::Serverless::Service’ Properties: Policies: – Version: ‘1’ Statement: – Effect: Allow Action: – ‘oss:ListObjects’ – ‘oss:GetObject’ – ‘oss:PutObject’ – ‘oss:DeleteObject’ – ‘fnf:*’ Resource: ‘*’ listObjects: Type: ‘Aliyun::Serverless::Function’ Properties: Handler: index.handler Runtime: python3 Timeout: 60 MemorySize: 128 CodeUri: functions/listobjects EnvironmentVariables: OSS_ENDPOINT: ‘https://oss-cn-hangzhou-internal.aliyuncs.com’ detectFaces: Type: ‘Aliyun::Serverless::Function’ Properties: Handler: index.handler Runtime: python3 Timeout: 60 MemorySize: 512 CodeUri: functions/detectfaces EnvironmentVariables: OSS_ENDPOINT: ‘https://oss-cn-hangzhou-internal.aliyuncs.com’ timer: Type: ‘Aliyun::Serverless::Function’ Properties: Handler: index.handler Runtime: python3 Timeout: 60 MemorySize: 512 CodeUri: functions/timer Events: timeTrigger: Type: Timer Properties: CronExpression: ‘0 * * * * *’ Enable: true # replace YOUR_BUCKET_NAME to your oss bucket name Payload: ‘{“flowName”: “oss-batch-process”, “input”: “{\”bucket\”: \”YOUR_BUCKET_NAME\”,\”prefix\”:\”\”}”}’ oss-batch-process: Type: ‘Aliyun::Serverless::Flow’ Properties: Description: batch process flow DefinitionUri: flows/index.flow.yml Policies: – AliyunFCInvocationAccess
  2. One-click deployment of functional computing and functional workflow resources to the cloud
  • Install the latest version of Fun
  • Execute Fun Deploy in the project root directory


Effect of validation

  1. Place the image in the root directory of the OSS Bucket




  1. After one minute, the timing trigger triggers the function to execute the function workflow.




  1. After the workflow is executed, view the OSS Bucket
  • Images tagged with faces were placed in the face-Detection directory






  • Processed videos are placed in the processed directory




conclusion

Through function calculation + function workflow, a service of face recognition based on batch image processing is built. The service divides the task into multiple steps because it uses the flow of a function workflow, and only needs to ensure that the function for each step can be completed within the time limit for function calculation (10 minutes).





The original link

This article is the content of Ali Cloud, shall not be reproduced without permission.