Using an SDK Sample Project

Detection and Classification(C++) Usage Guide

  1. Refer to Before You Start and Installing a MindX SDK Software Package to configure environment variables and install the MindX SDK software package.
  2. Create a Detection and Classification(C++) sample project. See Creating an Application Project.
  3. Prepare an input image.

    Manually download a non-progressive animal image (for example, a dog image), name it test.jpg, and upload it to the C++ directory of the project file in the environment.

  4. Download the .pb files of the YOLOv3 and ResNet-50 models from the Ascend developer community and upload them to the environments. For details, see Table 1.
    Table 1 Model obtaining

    Model

    Version

    How to Obtain

    YOLOv3

    1.6

    Link

    Keyword: YOLOv3

    Application Level: Released

    Framework: TensorFlow

    On the model page, confirm the model version and click Download to download the model. Alternatively, find the corresponding version in Version History and click Download.

    ResNet-50

    1.7

    Link

    Keyword: ResNet-50

    Application Level: Released

    Framework: TensorFlow

    On the model page, confirm the model version and click Download to download the model. Alternatively, find the corresponding version in Version History and click Download.

  5. Convert your model.
    Choose Ascend > Model Converter from the top menu bar on the project creation page.
    1. On the Model Information page, set the parameters as follows:
      • For details about the applicable parameters and configuration items of the YOLOv3 and ResNet-50 models, see Table 2.
      • For details about the results on the YOLOv3 model parameter configuration page, see Figure 2.
      • For details about the results on the ResNet-50 model parameter configuration page, see Figure 3.
      Table 2 Parameters in the Model Information area and applicable parameters of the YOLOv3 and ResNet-50 models

      Parameter

      Description

      Parameter Applicable to YOLOv3

      Parameter Applicable to ResNet-50

      Model File

      Sets the path of the model .pb file uploaded to the environment.

      Set the model .pb file path as required.

      Model Name

      Specifies the name of the generated model.

      Set this parameter to yolov3_tf_bs1_fp16.

      Set this parameter to resnet50_aipp_tf.

      Target SoC Version

      Sets the target SoC version.

      Select a value based on the actual chip type.

      OutputPath

      Model file output path.

      Use the default value.

      Input Format

      Specifies the input data format.

      Use the default value.

      input/input_data

      Specifies the input parameter for model conversion. Shape indicates the image shape information input to the model. Type indicates the data type of the specified input node.

      • Set Shape to 1,416,416,3.
      • Set Type to FP32.
      • Set Shape to 1,224,224,3.
      • Set Type to FP32.

      Output Nodes

      Displays the model output node information.

      1. Click Select.

        The page for selecting an output node is displayed.

      2. Right-click the found node and choose Select from the shortcut menu. See Figure 1.

      Select Conv_6/BiasAdd, Conv_14/BiasAdd, and Conv_22/BiasAdd.

      Do not need to set this parameter.

      Figure 1 Selecting an output node
      Figure 2 YOLOv3 model parameters
      Figure 3 ResNet-50 model parameters
    2. Click Next. In the Data Pre-Processing window, set parameters according to Figure 4. For details, see 2.
      Figure 4 Data preprocessing
    3. Click Next. In the Advanced Options Preview window, set parameters by referring to Figure 5.

      Enable Additional Arguments, and enter the absolute path of the model AIPP configuration file. Project_Path indicates the root directory of the SDK sample project. Replace it as required.

      When converting a YOLOv3 model, set the parameters as follows:

      --insert_op_conf=Project_Path/models/yolov3/aipp_yolov3_416_416.aippconfig

      When converting a ResNet-50 model, set the parameters as follows:

      --insert_op_conf=Project_Path/models/resnet50/aipp_resnet50_224_224.aippconfig
      Figure 5 Advanced options preview
    4. Click Finish to start model conversion.
  6. Find the generated OM model file in $HOME/modelzoo. Move the file to the root directory of the project file/models/resnet50 and root directory of the project file/models/yolov3.
  7. Build the application project.
    On the MindStudio project page, choose Build > Edit Build Configuration... from the top menu bar.
    1. Configure build parameters.
      Figure 6 shows a build configuration example. Select Release from the Build Type drop-down list and change the compilation group Name to Release. Then click OK. (If no configuration option exists, click to add one.)
      Figure 6 Build configuration
    2. Choose Build > Build CMake Project from the top menu bar to build the project.

      If no error message is displayed and the build progress reaches 100%, the build is successful. View the generated executable file main in the following directory:

      ├── Project name
      │   ├── C++
      │   │   ├──main        // Executable file
  8. Run the application project.
    1. Choose Run > Edit Configurations... from the top menu bar to access the run configuration page. Then, click + in the upper left corner and select CMake Application to configure the run configuration options.
      Figure 7 shows a configuration example. Because a relative path has been configured in the sample project, you need to set a relative working directory. In this example, set Working directory to the directory where the main file is located. After the configuration is complete, click Apply to save the run configuration and click OK to close the run configuration page.

      If you need to run an application project remotely, ensure that environment variables have been configured in the operating environment. For details, see Before You Start.

      Figure 7 Run configuration example of an SDK sample
    2. On the MindStudio project page, choose Run > Run... from the top menu bar. In the dialog box displayed, select the created run configuration and run the application.

      The following is an example of the code returned when the SDK sample project is successfully executed.

      Results:{"MxpiObject":[{"MxpiClass":[{"classId":163,"className":"beagle","confidence":0.87109375}],"classVec":[{"classId":16,"className":"dog","confidence":0.99641436299999997,"headerVec":[]}],"x0":125.63256800000001,"x1":918.29089399999998,"y0":116.434044,"y1":597.21276899999998}]}

    Before debugging this sample, modify the following content:

    1. Find the following command in C++/CMakeLists.txt:
      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,-z,now,-z,noexecstack  -s -pie")
    2. Change the command as follows:
      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,relro,-z,now,-z,noexecstack -pie")

Detection and Classification (Python) Usage Guide

  1. Refer to Before You Start and Installing a MindX SDK Software Package to configure environment variables and install the MindX SDK software package.
  2. Create the Detection and Classification(Python) sample project by referring to Creating an Application Project.
  3. Prepare an input image.

    Manually download an animal image (for example, a dog image), name it test.jpg, and upload it to the python directory of the project file in the environment.

  4. Download the .pb files of the YOLOv3 and ResNet-50 models from the Ascend developer community and upload them to the environments. For details, see Table 3.
    Table 3 Model obtaining

    Model

    Version

    How to Obtain

    YOLOv3

    1.6

    Link

    Keyword: YOLOv3

    Application Level: Released

    Framework: TensorFlow

    On the model page, confirm the model version and click Download to download the model. Alternatively, find the corresponding version in Version History and click Download.

    ResNet-50

    1.7

    Link

    Keyword: ResNet-50

    Application Level: Released

    Framework: TensorFlow

    On the model page, confirm the model version and click Download to download the model. Alternatively, find the corresponding version in Version History and click Download.

  5. Convert your model.
    Choose Ascend > Model Converter from the top menu bar on the project creation page.
    1. On the Model Information page, set the parameters as follows:
      • For details about the applicable parameters and configuration items of the YOLOv3 and ResNet-50 models, see Table 4.
      • For details about the results on the YOLOv3 model parameter configuration page, see Figure 9.
      • For details about the results on the ResNet-50 model parameter configuration page, see Figure 10.
      Table 4 Parameters in the Model Information area and applicable parameters of the YOLOv3 and ResNet-50 models

      Parameter

      Description

      Parameter Applicable to YOLOv3

      Parameter Applicable to ResNet-50

      Model File

      Sets the path of the model .pb file uploaded to the environment.

      Set the model .pb file path as required.

      Model Name

      Specifies the name of the generated model.

      Set this parameter to yolov3_tf_bs1_fp16.

      Set this parameter to resnet50_aipp_tf.

      Target SoC Version

      Sets the target SoC version.

      Select a value based on the actual chip type.

      OutputPath

      Model file output path.

      Use the default value.

      Input Format

      Specifies the input data format.

      Use the default value.

      input/input_data

      Specifies the input parameter for model conversion. Shape indicates the image shape information input to the model. Type indicates the data type of the specified input node.

      • Set Shape to 1,416,416,3.
      • Set Type to FP32.
      • Set Shape to 1,224,224,3.
      • Set Type to FP32.

      Output Nodes

      Displays the model output node information.

      1. Click Select.

        The page for selecting an output node is displayed.

      2. Right-click the found node and choose Select from the shortcut menu. See Figure 8.

      Select Conv_6/BiasAdd, Conv_14/BiasAdd, and Conv_22/BiasAdd.

      Do not need to set this parameter.

      Figure 8 Selecting an output node
      Figure 9 YOLOv3 model parameters
      Figure 10 ResNet-50 model parameters
    2. Click Next. In the Data Pre-Processing window, set parameters according to Figure 11. For details, see 2.
      Figure 11 Data preprocessing
    3. Click Next. In the Advanced Options Preview window, set parameters by referring to Figure 12.

      Enable Additional Arguments, and enter the absolute path of the model AIPP configuration file. Project_Path indicates the root directory of the SDK sample project. Replace it as required.

      When converting a YOLOv3 model, set the parameters as follows:

      --insert_op_conf=Project_Path/models/yolov3/aipp_yolov3_416_416.aippconfig

      When converting a ResNet-50 model, set the parameters as follows:

      --insert_op_conf=Project_Path/models/resnet50/aipp_resnet50_224_224.aippconfig
      Figure 12 Advanced options preview
    4. Click Finish to start model conversion.
  6. Find the generated OM model file in $HOME/modelzoo. Move the file to the root directory of the project file/models/resnet50 and root directory of the project file/models/yolov3.
  7. Run the application project.
    1. On the top menu bar of MindStudio, choose Run > Edit Configurations... to access the run configuration page.
    2. Click + in the upper left corner, create a Python run configuration option, and configure run parameters. (For details about how to configure the Python compiler, see Python SDK Dependency Settings.)

      Figure 13 shows a configuration example. After the configuration is complete, click Apply to save the run configuration and click OK to close the run configuration dialog box.

      Figure 13 Run configuration example of an SDK sample (Python)
    3. On the MindStudio project page, choose Run > Run... from the top menu bar. In the dialog box displayed, select the created run configuration and run the application.

      The following is an example of the code returned when the SDK sample project is successfully executed.

      {"MxpiObject":[{"MxpiClass":[{"classId":163,"className":"beagle","confidence":0.87109375}],"classVec":[{"classId":16,"className":"dog","confidence":0.99641436299999997,"headerVec":[]}],"x0":125.63256800000001,"x1":918.29089399999998,"y0":116.434044,"y1":597.21276899999998}]}