Updated on 2022-02-22 GMT+08:00

Example - Resource Management

The following is an example of resource management:

#! /usr/bin/python3.7

import hilens
import os

def run():
     # Obtain the path of the directory where the skill workspace is located. The path ends with a slash (/).
    skill_path = hilens.get_workspace_path()

    # Obtain the path of the directory where the skill model is located. The path ends with a slash (/).
    model_path = hilens.get_model_dir()

    # Obtain the skill configuration. If the information fails to be obtained, None is returned.
    skill_config = hilens.get_skill_config()
    # Assume that the face_dataset configuration item exists in the skill configuration and its value is the address of the face library file face_dataset.zip in OBS.
# Set skill configuration parameters. For details about how to set skill configuration parameters, see the User Guide.
    face_dataset_url = skill_config["face_dataset"]["value"]
    # Download the file from OBS to the skill workspace directory and check whether the download is successful based on the return value.
    ret = hilens.download_from_obs(face_dataset_url, hilens.get_workspace_path())
    if ret != 0:
        hilens.error("Failed to download from obs")
        return
    # Create a folder in the skill workspace directory and decompress it.
    os.system('mkdir '+hilens.get_workspace_path()+'face_dataset')
    os.system('unzip '+hilens.get_workspace_path()+'face_dataset.zip'+' -d '+hilens.get_workspace_path()+'face_dataset/')
        # Calculate the MD5 values of files.
    md5 = hilens.md5_of_file(hilens.get_workspace_path()+"face_dataset.zip")

if __name__ == '__main__':
    hilens.init("hello")
    run()
    hilens.terminate()

To set the skill configuration parameters, do as follows:

  1. Log in to the Huawei HiLens console and set runtime parameters during skill development. For details, see Creating Skills in the User Guide.
  2. After the skill development is complete, deploy the skill on your device. For details, see Deploying and Debugging Skills in the User Guide.
  3. After deploying the skill to your device, you can set runtime configuration parameters on the Skill Management page. For details, see Adding Runtime Configurations in the User Guide.