Help Center/ Huawei HiLens/ Best Practices/ Developing a Face Detection Skill
Updated on 2023-06-15 GMT+08:00

Developing a Face Detection Skill

Huawei HiLens allows developers to import (convert) models and develop skills. You can develop models, import them to Huawei HiLens, compile logic code based on service requirements, and create skills based on your custom algorithm models and logic code.

This chapter provides an example face detection skill to describe the overall process of creating a skill from importing a model to viewing the skill effect, helping you quickly get familiar with skill creation on Huawei HiLens.

Before you start, make the preparations described in Preparations. To develop a skill, perform the following steps:

Preparations

  • Make sure your HUAWEI CLOUD account is not in arrears or frozen.
  • Purchase a HiLens Kit device and prepare the network cable, computer, router, HDMI cable, and display.
  • Register the HiLens Kit device with the Huawei HiLens management console. For details, see Registering HiLens Kit Devices in the Huawei HiLens User Guide.
  • Create a bucket and folders in OBS for storing the sample model data. The OBS bucket is named hilens-test1, and the folders are face-detection and face-detection-output.

    For details about how to create an OBS bucket and folder, see Creating a Bucket and Creating a Folder. For successful model data access, ensure that the created OBS bucket and Huawei HiLens are in the same region.

    Operations that occupy OBS resources are billed. For details about the billing rules, see OBS Pricing Details.

Step 1: Prepare Data

Huawei HiLens provides a sample model named face_detection_model in the public OBS bucket. This chapter uses this model to develop a skill. Perform the following operations to upload the model file to the OBS directory hilens-test1/face-detection created in preparations.

  1. Download the sample model face_detection_model to the local host. Verify the signature in the directory where the file is stored (Git is recommended for Windows). After the verification is successful, OK is returned. Run the following command:

    echo ec5160c48f5ba6025dac696d7ff8b827f1902f6aa712b6969609cb5f290d149a face_detection_model.zip | sha256sum -c

  2. Decompress the face_detection_model package. For example, decompress the package to the face_detection_model folder on the local PC. The folder contains two subfolders: caffemodel+transfer and logic_code.
  3. Upload the three files in the caffemodel+transfer folder to the hilens-test1/face-detection OBS directory. For details, see Uploading a File. The three files are Caffe model files .caffemodel and .prototxt, and configuration file .cfg.

Step 2: Import (Convert) the Model

The imported models can be in .om, .pb, or .caffemodel format. Only models in .om format can run on HiLens Kit devices. Models in .pb or .caffemodel format can be automatically converted into the .om format by Huawei HiLens.

  1. Log in to the Huawei HiLens management console. In the navigation pane, choose Skill Development > Models. The Models page is displayed.
  2. On the Models page, click Import (Convert) Model in the upper right corner.
  3. On the Import Model page, set parameters according to Table 1. After confirming the information, click OK.

    Figure 1 Importing a model
    Table 1 Parameters for importing a model

    Parameter

    Recommended Configuration

    Name

    Enter face-detection-demo.

    Version

    Enter 1.0.0.

    Description

    Enter the description of the model to be imported.

    Model Source

    Click Import From OBS. In the Model Address area, click . Go to the /hilens-test1/face-detection/ directory where the model is uploaded, select the face_detection.caffemodel file, and click OK. See Figure 2 for more information.

    Type

    Select Caffe to Ascend.

    Import From

    After you select a model source, the path is automatically entered.

    Export To

    Click and select the /hilens-test1/face-detection-output/ directory.

    Advanced Options

    Set the input tensor shape and output node. In this example, retain the default values.

    Figure 2 Model source
    Figure 3 Importing a model

    After the model is imported, the Models page is displayed. You can view the model import (conversion) status in the list, including Converting, Conversion failed, Conversion succeeded, Import failed, and Import succeeded. When the status changes to Import succeeded, you can create skills on the Huawei HiLens management console.

Step 3: Create the Skill

  1. In the navigation pane of the Huawei HiLens management console, choose Skill Development > Skills.
  2. On the Basic Skills tab, click Create Skill in the upper right corner. The Create Skill page is displayed.
  3. On the Create Skill page, set Template to Create from scratch, and enter the basic information and skill content. In this example, you can skip (Optional) Runtime Configurations, (Optional) Hard Example Upload Settings, and (Optional) Elastic Skill Parameters.

    Basic Information

    Enter the basic information by referring to Table 2, as shown in Figure 4.
    Table 2 Basic information

    Parameter

    Recommended Configuration

    Template

    Select Create from scratch.

    Name

    Enter Face_Detection.

    Version

    Enter 1.0.0.

    Chip

    Retain the default value Ascend 310.

    Verification Value

    Set this parameter to test (the value of the init function parameter in the main.py file under the face_detection_model > logic_code folder downloaded in Step 1: Prepare Data). The verification value must be the same as the value of the init function parameter.

    Application Scenario

    Select Others and enter Face Detection in the text box.

    Icon

    Upload a skill icon.

    OS Platform

    Select Linux.

    Description

    Enter the description of the skill.

    Figure 4 Basic information

    Skill Content

    Based on your model and logic code, fill in the skill content by referring to Table 3, as shown in Figure 5.
    Table 3 Skill content parameters

    Parameter

    Recommended Configuration

    Skill Format

    Select Skill package.

    Runtime Language

    Select Python3.7.

    Code Execution Entry

    The default value is index.py. In this example, the code file name is main.py. Therefore, enter main.py.

    Model

    Click the plus sign (+). In the dialog box that is displayed, select the imported model face-detection-demo.

    Code Entry Mode

    1. Select Compile online and edit the code in the code editing box.

      Click and change the name of the default file index.py to main.py. Then, copy the code in the face_detection_model > logic_code > main.py file downloaded in Step 1: Prepare Data and paste it to the editing box of the main.py file.

    2. Choose File > Create Peer File, enter the file name postprocess.py, and click OK. Copy the code in the face_detection_model>logic_code>postprocess.py file downloaded in Step 1: Prepare Data and paste it to the editing box of the postprocess.py file.
    Figure 5 Skill content

  4. After entering the basic information and skill content, view the parameter values on the right of the page. If a parameter is incorrectly set, a red cross is displayed on the right.

    Confirm the information and click OK. The skill is successfully created.

    Figure 6 Confirming the information and creating a skill

After the skill is created, you can choose Skill Development > Skill Management to release the skill (in the Not Released state) to the skill market. You can also deploy the skill on devices and view the skill usage effect.

After the skill is released, its status becomes Reviewing. Huawei HiLens personnel will complete the review within three working days. After passing the review, the skill is in the Approved and released state.

Step 4: (Optional) Release the Skill

  1. Log in to the Huawei HiLens console, choose Skill Development > Skills in the left navigation pane. The Skills page is displayed.
  2. Select the skill to be released and click Release in the Operation column.
  3. In the displayed Release Skill dialog box, set the release information based on Table 4, and click OK.

    Table 4 Parameters for releasing skills

    Parameter

    Description

    Publish

    Service to which the skill is to be released. Select HiLens Skill Market in this example.

    Billing Policy

    Billing policy for releasing the skill to the skill market. The value can be Free or Charged.

    Billed By

    Billing mode after the skill is released.

    • If you select the Free billing policy, only One-off can be selected.
    • If you select the Charged billing policy, Yearly/Monthly and One-off can be selected.

    Measurement Unit

    Specifications that can be used on the device. The value can be Number of channels or QPS. If you select Number of channels, one license can be installed on a device to use one channel of video.

    Specification Limitation

    Maximum number of video channels that the skill can process on a device or the maximum number of concurrent video channels.

    Privacy Policy

    User privacy policies involved in this skill.

    After the release application is submitted, it will be sent to the Huawei HiLens background for review. The review will be completed within three working days.

Step 5: Install the Skill

  1. Choose Skill Development > Skills, select the developed skill, and click Install in the Operation column.
  2. Select a registered online device and click Install. After the installation is successful, click OK. See Figure 7.

    During the installation, the Huawei HiLens console will deliver the skill package to the device. It takes some time to deliver the skill package. You can view the skill installation progress in the progress bar. After the delivery is complete, the progress bar displays Installation succeeded. See Figure 7.
    Figure 7 Successful installation

    After the installation is successful, you can start the skill to view the skill output data.

Step 6: Start the Skill

  1. Use an HDMI video cable to connect the HiLens Kit video output port to the display.
  2. In the navigation pane, choose Device Management > Devices. The Devices page is displayed.
  3. Click the registered device. The Skill Management tab page is displayed. The status of the installed face detection skill is Stopped. Click Start in the Operation column and click OK to start the skill on the device.

    The skill status changes to Running after a short period of time, indicating that the skill is successfully running on the device.

    Table 5 lists the statuses of installed skills.
    Figure 8 Viewing skill status
    Table 5 Skill installation statuses

    Status

    Description

    Stopped

    The skill stops running on the device.

    Running

    The skill is successfully installed on the device and is running.

    When the skill is in the Running status, you can view the video data output by the skill on the display.
    Figure 9 Skill effect