Updated on 2024-09-30 GMT+08:00

Importing (Converting) Models

A skill can be abstractly understood as "algorithm model + logic code". The algorithm model handles AI inference, and the logic code handles inference result processing. Therefore, you need to import models to Huawei HiLens before developing skills.

Model Requirements

The models to be imported can be in .om, .pb, or .caffemodel format. Only models in .om format can run on HiLens Kit devices. If you import a model in .pb or .caffemodel format, the Huawei HiLens platform automatically converts it into the .om format.

Not all models can be successfully converted. Before importing and converting a model, check whether it uses the TensorFlow and Caffe operator boundaries supported by .om models. For details, see Caffe Operator Boundaries and TensorFlow Operator Boundaries.

Prerequisites

You can train a model in ModelArts or locally.

  • Importing a model trained locally

    Before importing a custom model, upload it to OBS. A non-om model package contains Caffe model files .caffemodel and .prototxt and configuration file .cfg, or TensorFlow model file .pb and configuration file .cfg.

    For details about how to upload model files to OBS, see Object Storage Service Getting Started. The directory to which the model files are uploaded must meet certain specifications. For details, see Model Input Directory Specifications.

    Uploading files to OBS is charged. For details about the OBS pricing, see Product Pricing Details.

    When uploading files to OBS, ensure that the OBS bucket and Huawei HiLens are in the same region and the OBS folder name meets the following requirements:

    • Cannot contain special characters: \:*?"<>|
    • Cannot start or end with a period (.) or slash (/).
    • The absolute path of the folder can contain a maximum of 1,023 characters.
    • Cannot contain two or more adjacent slashes (/).

Importing (Converting) a Model

  1. Log in to the Huawei HiLens console. In the navigation pane, choose Skill Development > Models. The Models page is displayed.
  2. Click Import (Convert) Model in the upper right corner.
  3. On the Import Model page, set parameters by referring to Table 1, confirm the information, and click OK.
    Figure 1 Importing a model
    Table 1 Parameters for importing a custom model

    Parameter

    Description

    Name

    Name of the model to be imported. A model name contains 2 to 24 characters. Only lowercase letters, digits, and hyphens (-) are allowed. It must start with a lowercase letter and end with a lowercase letter or digit.

    Version

    Version of the model to be imported.

    The value is in the number.number.number format, for example, 2.1.3. Each number ranges from 0 to 999. When it has two or more digits, it cannot start with 0.

    Description

    Description of the model to be imported. The value contains 1 to 100 characters. Special characters &!"'\<>= are not allowed.

    Model Source

    Select the source of the model to be imported. You can choose Import From OBS or Import From ModelArts..

    • Importing a model from OBS

      Click Import From OBS, select the bucket and folder where the custom model is stored on OBS, and click OK.

    • Importing a model from ModelArts
      1. Click Import From ModelArts and select a model framework from the drop-down list on the right, including TensorFlow, Caffe, and OM (obtained from the conversion task).

        After you import a TensorFlow or Caffe model, the Huawei HiLens platform converts it into the .om format and then imports it. The .om model is obtained from the previous conversion task.

      2. Select the model to be imported from the model list.

    Type

    If you select a model (non-om model) whose format needs to be converted for Model Source, you need to select a model conversion template, which can be TF-FrozenGraph-To-Ascend-HiLens, TF-SavedModel-To-Ascend-HiLens, TF-FrozenGraph-To-Ascend, TF-SavedModel-To-Ascend or Caffe to Ascend.

    • TF-FrozenGraph-To-Ascend-HiLens

      This template converts TensorFlow frozen_graph models into those run on Ascend chips. If the firmware version of your HiLens Kit system is 2.2.200.011, you are advised to use this template for model conversion.

    • TF-SavedModel-To-Ascend-HiLens

      This template converts TensorFlow saved_model models into those run on Ascend chips. If the firmware version of your HiLens Kit system is 2.2.200.011, you are advised to use this template for model conversion.

    • TF-FrozenGraph-To-Ascend

      This template converts TensorFlow frozen_graph models into those run on Ascend chips. If the firmware version of your HiLens Kit system is earlier than 2.2.200.011, you are advised to use this template for model conversion.

    • TF-SavedModel-To-Ascend

      This template converts TensorFlow saved_model models into those run on Ascend chips. If the firmware version of your HiLens Kit system is earlier than 2.2.200.011, you are advised to use this template for model conversion.

    • Caffe to Ascend

      Caffe models can be converted into models that can run on Ascend chips.

    • TF-FrozenGraph-To-Ascend-893

      This template converts TensorFlow frozen_graph models into those run on Ascend chips. If the firmware version of your HiLens Kit system is earlier than 2.2.200.011, you are advised to use this template for model conversion.

    Import From

    If you select a model (non-om model) that needs to be converted in Model Source, this parameter is automatically initialized based on the model source. The directory must contain the model file and configuration file required for conversion. For details about the input directory specifications of model files, see Model Input Directory Specifications.

    Export To

    If you select a model (non-om model) that needs to be converted in Model Source, click to select the OBS directory to which the converted model is exported. Ensure that no .om model exists in the directory. For details about the output directory specifications, see Model Output Directory Specifications.

    Advanced Options

    Includes the Input Tensor Shape and out_nodes parameters. For details, see Table 2.

    Table 2 Advanced Options

    Parameter

    Description

    Input Tensor Shape

    If you select a model (non-OM model) whose format needs to be converted for Model Source and the conversion type is TF-FrozenGraph-To-Ascend-HiLens or TF-SavedModel-To-Ascend-HiLens, you must enter the tensor shape.

    Input Tensor Shape indicates the shape of the input data of the model. The input data format is NHWC, for example, input_name:1,224,224,3. input_name must be the node name in the network model before model conversion. This parameter is mandatory when the model has dynamic shape input. For example, in input_name1:? ,h,w,c, the question mark (?) indicates the batch size, that is, the number of images processed at a time. It is used to convert the original model with a dynamic shape into an offline model with a fixed shape.

    Use commas (,) to separate multiple inputs.

    out_nodes

    Specifies the output node, for example, node_name1:0;node_name1:1;node_name2:0. node_name must be the node name in the network model before model conversion. The digit after each colon (:) indicates the sequence number of the output. For example, node_name1:0 indicates the 0th output of node_name1.

    input_format

    The default input data format is NHWC. If the actual format is NCHW, you need to set this parameter to NCHW.

    net_format

    Specifies the preferred data format for network operators. Possible values are ND (N cannot be more than 4) and 5D. This parameter only takes effect if the input data of operators on the network supports both ND and 5D formats. ND indicates that operators in the model are converted into the NCHW format. 5D indicates that operators in the model are converted into the Huawei-developed 5D format. 5D is the default value.

    fp16_high_prec

    Specifies whether to generate a high-precision FP16 Davinci model.

    • The default value is 0, indicating that a common FP16 Davinci model is generated, which has better inference performance.
    • The value 1 indicates that a high-precision FP16 Davinci model with better inference precision is generated.

    output_type

    FP32 is the default value and is recommended for classification and detection networks. For image super-resolution networks, UINT8 is recommended for better inference performance.

    After the model is imported, the Models page is displayed. You can view the imported model in the list.

Viewing Details About a Model

  1. Log in to the Huawei HiLens console. In the navigation pane, choose Skill Development > Models. The Models page is displayed.

    You can view the Model Name, Version, Model Size, Import Time, Status, Description, and Operation in the list. The model status can be Converting, Conversion failed, Conversion succeeded, Import failed, and Import succeeded.

  2. Click Details in the Operation column of a model. The Model Details page is displayed.

    You can view the Basic Information and Log Information of the model, as shown in Figure 2.

    Table 2 describes the Basic Information parameters.

    For the model that needs to be converted, you can enter keywords in the upper right corner of the Log Information area to quickly locate key information in a log.

    Figure 2 Model details

Reconverting a Model

If the imported model is not in the .om format and is in Conversion failed status, you can modify the model parameters and convert it again.

You can view the model status on the Models page of the Huawei HiLens console.

  1. Log in to the Huawei HiLens console. In the navigation pane, choose Skill Development > Models. The Models page is displayed.
  2. Click Details in the Operation column of a model. The Model Details page is displayed.

    You can view the Basic Information and Log Information of the model.

    For the model that needs to be converted, you can enter keywords in the upper right corner of the Log Information area to quickly locate key information in a log.

  3. On the Basic Information tab page, click to modify the Type, Advanced Options, Import From, Export To, and Description parameters. After the modification is complete, click to save the modification. Table 2 describes related parameters.
  4. After modifying the model parameters, click Reconvert in the upper right corner to convert the model again.

Deleting a Model

You can delete imported (converted) models based on service requirements. Models in the Converting state cannot be deleted.

  1. Log in to the Huawei HiLens console. In the navigation pane, choose Skill Development > Models. The Models page is displayed.
  2. Locate a model and click Delete in the Operation column to delete it. You can also click Details in the Operation column and click Delete Model in the upper right corner of the model details page to delete the model.
    Figure 3 Deleting a model