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.
Before using an open source application, ensure that:
- Mind Studio has been installed. For details, see Mind Studio Installation Guide.
- 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. For details, see Atlas 200 DK User Guide.
Before running the application, obtain the source code package and configure the environment as follows.
-
Obtain the source code package.
Download all the code in the sample-facedetection 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.
-
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
- 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
-
Access the root directory where the facial recognition application code is located as the Mind Studio installation user, for example, /home/ascend/sample-facialrecognition.
-
Run the deployment script to prepare the project environment, including compiling and deploying the ascenddk public library, downloading the network model, and configuring Presenter Server.
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 network model file and the dependent common code library to the /sample-facialrecognition/script directory, by referring to Downloading Network Models and Dependency 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 model file and dependency 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: 12107.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 a 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 will automatically create it.
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 1.
-
-
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 presenterserve 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 2 shows that the presenter_server service is started successfully.
Figure 2 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.
-
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.
- camera_channel_name: Indicates the channel to which a camera belongs. The value can be Channel-1 or Channel-2. For details, see Atlas 200 DK User Guide.
Example command:
bash run_facialrecognitionapp.sh 192.168.1.2 video Channel-1 &
-
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 4 shows the Presenter Server page.
Figure 4 Presenter Server page
- 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.
-
Register a face.
-
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.
-
Stopping the Facial Recognition Application
The facial recognition application is running continuously 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 network models
The models used in the Facial Recognition application are converted models that adapt to the Ascend 310 chipset. For details about how to download this kind of models and the original network models, see Table 1. If you have a better model solution, you are welcome to share it at https://github.com/Ascend/models.
Download the network models files (.om files) to the sample-facialrecognition/script directory.
Table 1 Models used in Atlas DK open source applications
This model is used in the facial recognition applications.
It is a network model converted from ResNet0-SSD300 model based on Caffe.
Download the model from the computer_vision/object_detect/face_detection directory in the https://github.com/Ascend/models/ repository.
For the version description, see the README.md file in the current directory.
For details, see the README.md file of the computer_vision/object_detect/face_detection directory in the https://github.com/Ascend/models/ repository.
Precautions during model conversion:
During the conversion, a message is displayed indicating that the conversion fails. You only need to select SSDDetectionOutput from the drop-down list box for the last layer and click Retry.
This model is used in the facial recognition application.
It is a network model converted from the VanillaCNN model based on Caffe.
Download the model from the computer_vision/classification/vanillacnn directory in the https://github.com/Ascend/models/ repository.
For the version description, see the README.md file in the current directory.
For details, see the README.md file of the computer_vision/classification/vanillacnn directory in the https://github.com/Ascend/models/ repository.
Precautions during model conversion:
For details about the configuration during conversion, see Figure 5.
This model is used in the facial recognition application.
It is a network model converted from the SphereFace model based on Caffe.
Download the model from the computer_vision/classification/sphereface directory in the https://github.com/Ascend/models/ repository.
For the version description, see the README.md file in the current directory.
For details, see the README.md file of the computer_vision/classification/sphereface directory in the https://github.com/Ascend/models/ repository.
Precautions during model conversion:
For details about the configuration during conversion, see Figure 6.
Figure 5 Configuration for the VanillaCNN model during conversion
- Input Shape: The value of N is 4, indicating that four images are processed each time. The value of this parameter must be the same as the value of batch_size in the corresponding model in the graph.config file.
- Input Image Preprocess: Set this parameter to Off.
Figure 6 Configuration for the Sphereface model during conversion
- Input Shape: The value of N is 8, indicating that eight images are processed each time. The value of this parameter must be the same as the value of batch_size in the corresponding model in the graph.config file.
- Input Image Format: Enter the image format. In this example, this parameter is set to** RGB888_U8**.
- Input Image Size[W|H]: Since the format of the input image is RGB8888_U8, 128 x 16 alignment is not required. Use the width and height required by the model, that is, 96 and 112, respectively.
- Mean Less[B|G|R]: Indicates the mean value of the image used in the model training. The value can be obtained from the sphereface_model.prototxt file of the model.
- Multiplying Factor[B|G|R]: Indicates the multiply coefficient of the image used in this model training. The value can be obtained from the** sphereface_model.prototxt** file of the model (that is, the value of scale).
-
Download the dependent software libraries
Download the dependent software libraries to the sample-facialrecognition/script directory.
Table 2 Download the dependent software libraries
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-presenter/tree/master/presenteragent
tornado (5.1.0)
protobuf (3.5.1)
numpy (1.14.2)
Search for related sources and install them.