Skip to content

Latest commit

 

History

History
170 lines (110 loc) · 12.3 KB

File metadata and controls

170 lines (110 loc) · 12.3 KB

EN|CN

Object Detection

The object detection application runs on the Atlas 200 DK or the AI acceleration cloud server and implements the inference function by using Faster R-CNN object detection network.

Prerequisites

Before using an open source application, ensure that:

  • Mind Studio has been installed.
  • The Atlas 200 DK developer board has been connected to Mind Studio, the cross compiler has been installed, the SD card has been prepared, and basic information has been configured.

Software Preparation

Before running the application, obtain the source code package and configure the environment as follows.

  1. Obtain the source code package.

    Download all the code in the sample-objectdetection repository to any directory on Ubuntu Server where Mind Studio is located as the Mind Studio installation user, for example, /home/ascend/sample-objectdetection.

  2. Obtain the source network model required by the application.

    Obtain the source network model and its weight file used in the application by referring to Table 1, and save them to any directory on the Ubuntu server where Mind Studio is located (for example, $HOME/ascend/models/faster_rcnn).

    Table 1 Models used in the detection network application

    Model Name

    Model Description

    Model Download Path

    faster_rcnn

    Network model for object detection.

    It is a Faster R-CNN model based on Caffe.

    Download the source network model file and its weight file by referring to README.md in https://github.com/Ascend/models/tree/master/computer_vision/object_detect/faster_rcnn.

  3. Convert the source network model to a Da Vinci model.

    1. Choose Tool > Convert Model from the main menu of Mind Studio. The Convert Model page is displayed.

    2. On the Convert Model page, set Model File and Weight File to the model file and weight file downloaded in 2, respectively.

      • Set Model Name to the model name in Table 1: faster_rcnn.

      • Retain default values for other parameters.

        Figure 1 faster_rcnn model conversion configuration

    3. Click OK to start model conversion.

      After successful conversion, a .om Da Vinci model file is generated in the $HOME/tools/che/model-zoo/my-model/fast_rcnn directory.

  4. Log in to Ubuntu Server where Mind Studio is located as the Mind Studio installation user and set the environment variable DDK_HOME.

    vim ~/.bashrc

    Run the following commands to add the environment variables DDK_HOME and LD_LIBRARY_PATH to the last line:

    export DDK_HOME=/home/XXX/tools/che/ddk/ddk

    export LD_LIBRARY_PATH=$DDK_HOME/uihost/lib

    NOTE:

    • XXX indicates the Mind Studio installation user, and /home/XXX/tools indicates the default installation path of the DDK.
    • If the environment variables have been added, skip this step.

    Enter :wq! to save and exit.

    Run the following command for the environment variable to take effect:

    source ~/.bashrc

Deployment

  1. Access the root directory where the cvnetworkverify application code is located as the Mind Studio installation user, for example, /home/ascend/sample-objectdetection.

  2. Run the deployment script to prepare the project environment, including compiling and deploying the ascenddk public library and application.

    bash deploy.sh host_ip model_mode

    • host_ip: For the Atlas 200 DK developer board, this parameter indicates the IP address of the developer board. For the AI acceleration cloud server, this parameter indicates the IP address of the host.
    • model_mode indicates the deployment mode of the model file. The default setting is internet.
      • local: If the Ubuntu system where Mind Studio is located is not connected to the network, use the local mode. In this case, download the dependent common code library ezdvpp to the sample-objectdetection/script directory by referring to the Downloading Dependent Code Library.
      • internet: Indicates the online deployment mode. If the Ubuntu system where Mind Studio is located is connected to the network, use the Internet mode. In this case, download the dependent code library ezdvpp online.

    Example command:

    bash deploy.sh 192.168.1.2

  3. Upload the generated Da Vinci offline model and images to be inferred to the directory of the HwHiAiUser user on the host. For details, see Table 1.

    For example, upload the model file faster_rcnn.om to the /home/HwHiAiUser/models directory on the host.

    The image requirements are as follows:

    • Format: JPG, PNG, and BMP.
    • Width of the input image: the value is an integer ranging from 16px to 4096px.
    • Height of the input image: the value is an integer ranging from 16px to 4096px.

Running

  1. Log in to the Host as the HwHiAiUser user in SSH mode on Ubuntu Server where Mind Studio is located.

    ssh HwHiAiUser@host_ip

    For the Atlas 200 DK, the default value of host_ip is 192.168.1.2 (USB connection mode) or 192.168.0.2 (NIC connection mode).

    For the AI acceleration cloud server, host_ip indicates the IP address of the server where Mind Studio is located.

  2. Go to the path of the executable file of object detection application.

    cd ~/HIAI_PROJECTS/ascend_workspace/objectdetection/out

  3. Run the application.

    Run the run_object_detection_faster_rcnn.py script to save the images which are generated by inference to the specified path.

    Example command:

    python3 run_object_detection_faster_rcnn.py -m ~/models/faster_rcnn.om -w 800 -h 600 -i

    ./example.jpg -o ./out -c 21

    • -m/--model_path: offline model path
    • -w/model_width: width of the input image of a model. The value is an integer ranging from 16 to 4096.
    • -h/model_height: height of the input image of a model. The value is an integer ranging from 16 to 4096.
    • -i/input_path: directory or path of the input image. You can enter multiple paths.
    • -o/output_path: directory for storing output images. The default setting is the current directory.
    • -c/output_categories: number of Faster R-CNN detection categories (including the background). The value is an integer ranging from 2 to 32. The default value is 21.

    For other parameters, run the python3 run_object_detection_faster_rcnn.py --help command. For details, see the help information.

Downloading Dependent Code Library

Download the dependent software libraries to the sample-objectdetection/script directory.

Table 2 Download the dependent software library

Module Name

Module Description

Download Address

EZDVPP

Encapsulates the DVPP interface and provides image and video processing capabilities, such as color gamut conversion and image / video conversion

https://github.com/Ascend/sdk-ezdvpp

After the download, keep the folder name ezdvpp.