Performing Inference on an AscendCL Application Project

Data Preparation

  1. Obtain the input images of this sample from the following links and perform operations based on the actual application scenario.

    Links: Data image 1 and Data image 2

  2. Upload the obtained file to the project_directory/data directory in the development environment as the running user.
  3. Log in to the development environment as the running user.
  4. Switch to the project_directory/data directory and run the transferPic.py script.
    Convert the .jpg files to the .bin files and resize the images from 1024 x 683 to 224 x 224. Find the generated two .bin files in the project_directory/data directory.
    python3 ../script/transferPic.py

    If you get the following error message during script execution, the Pillow library is missing. Run the pip3 install Pillow --user command to install the Pillow library.

    ModuleNotFoundError: No module named 'PIL'

Application Development

After an application project is created, in the src directory you can find the .cpp template code of the application for system initialization, model execution, model uninstallation, resource destruction, and more. To use the code, you only need to make the following modifications to sample_process.cpp based on the model file name, image name, and path (relative path only).

Change the image file names and paths, and the OM model path after offline conversion as needed.

Figure 1 Modification example

In the template code, APIs prefixed with acl are available to users. For details about the APIs, see "AscendCL API Reference" in the AscendCL Application Software Development Guide (C&C++).

Application Project Build and Run

  1. Perform build configuration.
    On the MindStudio project page, choose Build > Edit Configurations... from menu bar to enter the build configuration page.
    1. Set build parameters and click to add configurations.

      The configuration option marked with (default) in the list is the default one. To switch the default option to a custom option, select the custom option and click .

      Figure 2 Build configuration
    2. Click OK to save the build project.
  2. On the MindStudio project page, choose Build > Build CMake Project from the top menu bar to use the default configurations for incremental build.

    If no error message is displayed during the build process and the message "Build finished" is displayed, the build is successful.

    Figure 3 Example of successful build

    After the build is complete, the main file is generated in the out directory of the current project directory.

  3. Choose Run > Edit Configurations... from the menu bar. The run configuration page is displayed.
  4. Choose > CMake Application to add and configure run parameters of the application project. Figure 4 shows a configuration example.
    Figure 4 Run/Debug Configurations dialog box
    • Executable: Select the path of the build executable file to the last level.
    • Working directory: working directory. (If a relative path is configured in the project, you need to select a relative working directory.)
  5. After the configuration is complete, click Apply to save the run configuration and click OK to close the run configuration dialog box.
  6. 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.

    • If no error message is displayed and the message "** finished **" is displayed, the execution is complete.
    • If an error message is displayed during application execution, check the detailed logs of the operating environment. For details, see the Log Reference.
      • The default log path is $HOME/ascend/log. For details, see the "Log Files" section.
      • The default log level is ERROR. For details about how to query or change the log level, see the "Log Level Setting" section.