Git Product home page Git Product logo

sample-facialrecognition's Introduction

EN|CN

Facial Recognition

Developers can deploy the application on the Atlas 200 DK to register a face, predict the face information in the video by using the camera, and compare the predicted face with the registered face to predict the most possible user.

Prerequisites

Before using an open source application, ensure that:

  • Mind Studio has been installed.
  • The Atlas 200 DK developer board has been connected to Mind Studio, the cross compiler has been installed, the SD card has been prepared, and basic information has been configured.

Software Preparation

Before running the application, obtain the source code package and configure the environment as follows.

  1. Obtain the source code package.

    Download all the code in the sample-facialrecognition repository at https://github.com/Ascend/sample-facialrecognition to any directory on Ubuntu Server where Mind Studio is located as the Mind Studio installation user, for example, /home/ascend/sample-facialrecognition.

  2. Obtain the source network model required by the application.

    Obtain the source network model and its weight file used in the application by referring to Table 1, and save them to any directory on the Ubuntu server where Mind Studio is located (for example, $HOME/ascend/models/facialrecognition).

    Table 1 Models used for facial recognition

    Model Name

    Model Description

    Model Download Path

    face_detection

    Network model for face detection.

    It is a network model converted from ResNet0-SSD300 model based on Caffe.

    Download the source network model file and its weight file by referring to README.md in https://github.com/Ascend/models/tree/master/computer_vision/object_detect/face_detection.

    vanillacnn

    Network model for marking facial feature points.

    It is a network model converted from the VanillaCNN model based on Caffe.

    Download the source network model file and its weight file by referring to README.md in https://github.com/Ascend/models/tree/master/computer_vision/classification/vanillacnn.

    sphereface

    Network model for obtaining feature vectors.

    It is a network model converted from the SphereFace model based on Caffe.

    Download the source network model file and its weight file by referring to README.md in https://github.com/Ascend/models/tree/master/computer_vision/classification/sphereface.

  3. Convert the source network model to a Da Vinci model.

    1. Choose Tool > Convert Model from the main menu of Mind Studio. The Convert Model page is displayed.

    2. On the Convert Model page, set** Model File** and Weight File to the model file and weight file downloaded in Step 2, respectively.

      • Set Model Name to the model name in Table 1.

      • Configure model conversion for the VanillaCNN and SphereFace models by referring to Figure 1 and Figure 2, respectively.

        Figure 1 VanillaCNNModel Model Conversion Configuration Reference

        • For Input Shape, N:4 indicates that 4 images are processed each time. The value of this parameter must be the same as the value of batch_size of the corresponding model in graph.config.
        • Set Input Image Preprocess to off.

        Figure 2 SpherefaceModel Model Conversion Configuration Reference

        • For Input Shape, N:8 indicates that 8 images are processed each time for the facial recognition application. The value of this parameter must be the same as the value of batch_size of the corresponding model in graph.config.
        • Set Input Image Format to RGB888_U8.
        • Set Input Image Size[W|H] to 96 and 112. In this example, the input image format is RGB8888_U8. Therefore, 128 x 16 alignment is not required.
        • Set Mean Less[B|G|R] to the man value of the images used in the model training. The value can be obtained from the sphereface_model.prototxt file of the model.
        • Set Multiplying Factor[B|G|R] to the multiplication factor of the images used in the model training. The value can be obtained from the** sphereface_model.prototxt** file of the model, that is, the value of scale.
    3. Click OK to start model conversion.

      During the conversion of the face_detection model, the following error will be reported.

      Figure 3 Model conversion error

      Select SSDDetectionOutput from the Suggestion drop-down list box at the DetectionOutput layer and click Retry.

      After successful conversion, a .om Da Vinci model is generated in the $HOME/tools/che/model-zoo/my-model/xxx directory.

  4. Upload the converted .om model file to the sample-facialrecognition/script directory in the source code path in 1.

  5. Log in to Ubuntu Server where Mind Studio is located as the Mind Studio installation user and set the environment variable DDK_HOME.

    vim ~/.bashrc

    Run the following commands to add the environment variables DDK_HOME and LD_LIBRARY_PATH to the last line:

    export DDK_HOME=/home/XXX/tools/che/ddk/ddk

    export LD_LIBRARY_PATH=$DDK_HOME/uihost/lib

    NOTE:

    • XXX indicates the Mind Studio installation user, and /home/XXX/tools indicates the default installation path of the DDK.
    • If the environment variables have been added, skip this step.

    Enter :wq! to save and exit.

    Run the following command for the environment variable to take effect:

    source ~/.bashrc

Deployment

  1. Access the root directory where the facial recognition application code is located as the Mind Studio installation user, for example, /home/ascend/sample-facialrecognition.

  2. Run the deployment script to prepare the project environment, including compiling and deploying the ascenddk public library, and configuring Presenter Server. The Presenter Server is used to receive the data sent by the application and display the result through the browser.

    bash deploy.sh host_ip model_mode

    • host_ip: this parameter indicates the IP address of the Atlas 200 DK developer board.

    • model_mode indicates the deployment mode of the model file. The default setting is internet.

      • local: If the Ubuntu system where Mind Studio is located is not connected to the network, use the local mode. In this case, download the dependent common code library to the /sample-facialrecognition/script directory, by referring to Downloading Dependent Code Library.
      • internet: If the Ubuntu system where Mind Studio is located is connected to the network, use the Internet mode. In this case, download the dependent code library online.

    Example command:

    bash deploy.sh 192.168.1.2 internet

    • When the message Please choose one to show the presenter in browser(default: 127.0.0.1): is displayed, enter the IP address used for accessing the Presenter Server service in the browser. Generally, the IP address is the IP address for accessing the Mind Studio service.
    • When the message Please input an absolute path to storage facial recognition data: is displayed, enter the path for storing face registration data and parsing data in Mind Studio. The Mind Studio user must have the read and write permissions. If the path does not exist, the script is automatically created.

    Select the IP address used by the browser to access the Presenter Server service in Current environment valid ip list and enter the path for storing facial recognition data, as shown in Figure 4.

    Figure 4 Project deployment

  3. Start Presenter Server.

    Run the following command to start the Presenter Server program of the facial recognition application in the background:

    python3 presenterserver/presenter_server.py --app facial_recognition &

    NOTE:
    presenter_server.py is located in the presenterserver directory. You can run the python3 presenter_server.py -h or python3 presenter_server.py --help command in this directory to view the usage method of presenter_server.py.

    Figure 5 shows that the presenter_server service is started successfully.

    Figure 5 Starting the Presenter Server process

    Use the URL shown in the preceding figure to log in to Presenter Server (only the Chrome browser is supported). The IP address is that entered in 2 and the default port number is 7009. The following figure indicates that Presenter Server is started successfully.

    Figure 6 Home page

    The following figure shows the IP address used by the Presenter Server and Mind Studio to communicate with the Atlas 200 DK.

    Figure 7 Example IP Address

    Where:

    • The IP address of the Atlas 200 DK developer board is 192.168.1.2 (connected in USB mode).
    • The IP address used by the Presenter Server to communicate with the Atlas 200 DK is in the same network segment as the IP address of the Atlas 200 DK on the UI Host server. For example: 192.168.1.223.
    • The following is an example of accessing the IP address of the Presenter Server using a browser: 10.10.0.1, because the Presenter Server and Mind Studio are deployed on the same server, the IP address is also the IP address for accessing the Mind Studio through the browser.

Running

  1. Run the facial recognition application.

    Run the following command in the sample-facialrecognition directory to start the facial recognition application:

    bash run_facialrecognitionapp.sh host_ip presenter_view_app_name camera_channel_name &

    • host_ip: For the Atlas 200 DK developer board, this parameter indicates the IP address of the developer board.

    • presenter_view_app_name: Indicates App Name displayed on the Presenter Server page, which is user-defined. The value of this parameter must be unique on the Presenter Server page, which contains only case-senstive leters, digits, and underscores(_). The number of characters should be 3-20.

    • camera_channel_name: Indicates the channel to which a camera belongs. The value can be Channel-1 or Channel-2.

      For details, see View the Channel to Which a Camera Belongs in Atlas 200 DK User Guide.

    • Example command:

    bash run_facialrecognitionapp.sh 192.168.1.2 video Channel-1 &

  2. Use the URL that is displayed when you start the Presenter Server service to log in to the Presenter Server website (only the Chrome browser is supported).

    Figure 8 shows the Presenter Server page.

    Figure 8 Presenter Server page

    NOTE:

    • The Presenter Server of the facial recognition application supports a maximum of two channels at the same time (each presenter_view_app_name corresponds to a channel).
    • Due to hardware limitations, the maximum frame rate supported by each channel is 20fps, a lower frame rate is automatically used when the network bandwidth is low.
  3. Register a face.

    1. Click the Face Library tab and enter a user name in the Username text box.

    2. Click Browse to upload a face image. Crop the face image based on the ratio of Example Photo.

    3. Click Submit. If the upload fails, you can change the cropping ratio.

  4. Perform facial recognition and comparison.

    On the App List tab page, click video for example in the App Name column. If a face is displayed in the camera and matches the registered face, the name and similarity information of the person are displayed.

Follow-up Operations

  • Stopping the Facial Recognition Application

    The facial recognition application is running continually after being executed. To stop it, perform the following operation:

    Run the following command in the sample-facialrecognition directory as the Mind Studio installation user:

    bash stop_facialrecognitionapp.sh host_ip

    host_ip: For the Atlas 200 DK developer board, this parameter indicates the IP address of the developer board.

    Example command:

    bash stop_facialrecognitionapp.sh 192.168.1.2

  • Stopping the Presenter Server Service

    The Presenter Server service is always in the running state after being started. To stop the Presenter Server service of the facial recognition application, perform the following operations:

    Run the following command to check the process of the Presenter Server service corresponding to the facial recognition application as the Mind Studio installation user:

    ps -ef | grep presenter | grep facial_recognition

    ascend@ascend-HP-ProDesk-600-G4-PCI-MT:~/sample-facialrecognition$ ps -ef | grep presenter | grep facial_recognition 
    ascend 22294 20313 22 14:45 pts/24?? 00:00:01 python3 presenterserver/presenter_server.py --app facial_recognition
    

    In the preceding information, 22294 indicates the process ID of the Presenter Server service corresponding to the facial recognition application.

    To stop the service, run the following command:

    kill -9 22294

Downloading Dependent Code Library

Download the dependent software libraries to the /sample-facialrecognition/script directory.

Table 2 Download the dependent software library

Module Name

Module Description

Download Address

EZDVPP

Encapsulates the DVPP interface and provides image and video processing capabilities, such as color gamut conversion and image / video conversion

https://github.com/Ascend/sdk-ezdvpp

After the download, keep the folder name ezdvpp.

Presenter Agent

API for interacting with the Presenter Server.

https://github.com/Ascend/sdk-presenter/tree/master

Obtain the presenteragent folder in this path, after the download, keep the folder name presenteragent.

tornado (5.1.0)

protobuf (3.5.1)

numpy (1.14.2)

Python libraries that Presenter Server depends on.

You can search for related packages on the Python official website https://pypi.org/ for installation. If you run the pip3 install command to download the file online, you can run the following command to specify the version to be downloaded: pip3 install tornado==5.1.0 -i Installation source of the specified library --trusted-host Host name of the installation source

sample-facialrecognition's People

Contributors

ascendhuawei avatar swxemily avatar fuleige avatar t00354296 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.