# sample-objectdetection **Repository Path**: LouisLoufy/sample-objectdetection ## Basic Information - **Project Name**: sample-objectdetection - **Description**: 本Application支持运行在Atlas 200 DK或者AI加速云服务器上,实现了对faster-rcnn目标检测网络的推理功能 - **Primary Language**: C++ - **License**: Apache-2.0 - **Default Branch**: 1.3x.0.0 - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2023-03-17 - **Last Updated**: 2023-03-17 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README English|[中文](Readme.md) **This case is only used for learning. It is not responsible for the effect and does not support commercial use.** # Object Detection This application can run on the Atlas 200 DK or the AI acceleration cloud server to implement the inference function by using Faster R-CNN object detection network. The applications in the current version branch adapt to [DDK&RunTime](https://ascend.huawei.com/resources) **1.32.0.0 and later**. ## Prerequisites Before deploying this sample, 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. ## Deployment You can use either of the following methods: 1. Quick deployment: visit [https://gitee.com/Atlas200DK/faster-deploy](https://gitee.com/Atlas200DK/faster-deploy). >![](public_sys-resources/icon-note.gif) **NOTE:** >- The quick deployment script can be used to deploy multiple samples rapidly. Select **objectdetection**. >- The quick deployment script automatically completes code download, model conversion, and environment variable configuration. To learn about the detailed deployment process, select the common deployment mode. Go to [2. Common deployment](#en-us_topic_0228461892_li3208251440). 2. Common deployment: visit [https://gitee.com/Atlas200DK/sample-README/tree/master/sample-objectdetection](https://gitee.com/Atlas200DK/sample-README/tree/master/sample-objectdetection). >![](public_sys-resources/icon-note.gif) **NOTE:** >- In this deployment mode, you need to manually download code, convert models, and configure environment variables. After that, you will have a better understanding of the process. ## Build 1. Open the project. Go to the directory that stores the decompressed installation package as the Mind Studio installation user in CLI mode, for example, **$HOME/MindStudio-ubuntu/bin**. Run the following command to start Mind Studio: **./MindStudio.sh** Open the **sample\_objectdetection** project, as shown in [Figure 1](#en-us_topic_0228461892_en-us_topic_0203223280_fig05481157171918). **Figure 1** Opening the objectdetection project ![](figures/en-us_image_0208253269.png) 2. Configure project information in the **src/param\_configure.conf** file. **Figure 2** Configuration file path ![](figures/configuration-file-path.png "configuration-file-path") The default configurations of the configuration file are as follows: ``` remote_host=192.168.1.2 ``` **remote\_host**: IP address of the Atlas 200 DK developer board >![](public_sys-resources/icon-note.gif) **NOTE:** >- Do not use double quotation marks \(""\) during parameter settings. >- Modify the default configurations as required. 3. Run the **deploy.sh** script to adjust configuration parameters and download and compile the third-party library. Open the **Terminal** window of Mind Studio. By default, the home directory of the code is used. Run the **deploy.sh** script in the background to deploy the environment, as shown in [Figure 3](#en-us_topic_0228461892_en-us_topic_0203223280_fig1224920422716). **Figure 3** Running the deploy.sh script ![](figures/running-the-deploy-sh-script.png "running-the-deploy-sh-script") >![](public_sys-resources/icon-note.gif) **NOTE:** >- During the first deployment, if no third-party library is used, the system automatically downloads and builds the third-party library, which may take a long time. The third-party library can be directly used for the subsequent build. >- During deployment, select the IP address of the host that communicates with the developer board. Generally, the IP address is the IP address configured for the virtual NIC. If the IP address is in the same network segment as the IP address of the developer board, it is automatically selected for deployment. If they are not in the same network segment, you need to manually type the IP address of the host that communicates with the Atlas DK to complete the deployment. 4. Start building. Open Mind Studio and choose **Build \> Build \> Build-Configuration** from the main menu. The **build** and **run** folders are generated in the directory, as shown in [Figure 4](#en-us_topic_0228461892_en-us_topic_0203223280_fig19291111318376). **Figure 4** Build and file generation ![](figures/build-and-file-generation.png "build-and-file-generation") Notes: When you build a project for the first time, **Build \> Build** is unavailable. You need to choose **Build \> Edit Build Configuration** to set parameters before the build. ![](figures/build_configuration.png) 5. Upload the images to be inferred to any directory of the **HwHiAiUser** user on the host side. The image requirements are as follows: - Format: jpg, png, and bmp - Width of the input image: an integer ranging from 16px to 4096px - Height of the input image: an integer ranging from 16px to 4096px ## Run 1. On the toolbar of Mind Studio, click **Run** and choose **Run \> Run 'sample-objectdetection'**. As shown in [Figure 5](#en-us_topic_0228461892_en-us_topic_0203223280_fig18918132273612), the executable application is running on the developer board. **Figure 5** Running application ![](figures/running-application.png "running-application") You can ignore the error information reported during the execution because Mind Studio cannot transfer parameters for an executable application. In the preceding steps, the executable application and dependent library files are deployed to the developer board. You need to log in to the developer board in SSH mode and manually execute the files in the corresponding directory. For details, see the following steps. 2. Log in to the host side 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\). 3. Go to the path of the executable file of Faster R-CNN detection application. Command example: **cd \~/HIAI\_PROJECTS/workspace\_mind\_studio/sample\_objectdetection\__XXXXX_/out** >![](public_sys-resources/icon-note.gif) **NOTE:** >- In this path, _**xxxxx **_in** sample\_objectdetection\__xxxxx_** is a combination of letters and digits generated randomly each time the application is built. 4. 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. Command example: **python3 run\_object\_detection\_faster\_rcnn.py -w _800_ -h _600_ -i _./example.jpg_ -o _./out_ -c _21_** - **-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 the output image. 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**. 5. For other parameters, run the **python3 run\_object\_detection\_faster\_rcnn.py --help** command. For details, see the help information.