README.md 6.1 KB
Newer Older
G
Guanghua Yu 已提交
1 2 3 4 5 6 7
<!--- Licensed to the Apache Software Foundation (ASF) under one -->
<!--- or more contributor license agreements.  See the NOTICE file -->
<!--- distributed with this work for additional information -->
<!--- regarding copyright ownership.  The ASF licenses this file -->
<!--- to you under the Apache License, Version 2.0 (the -->
<!--- "License"); you may not use this file except in compliance -->
<!--- with the License.  You may obtain a copy of the License at -->
G
Guanghua Yu 已提交
8

G
Guanghua Yu 已提交
9
<!---   http://www.apache.org/licenses/LICENSE-2.0 -->
G
Guanghua Yu 已提交
10

G
Guanghua Yu 已提交
11 12 13 14 15 16 17
<!--- Unless required by applicable law or agreed to in writing, -->
<!--- software distributed under the License is distributed on an -->
<!--- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -->
<!--- KIND, either express or implied.  See the License for the -->
<!--- specific language governing permissions and limitations -->
<!--- under the License. -->

G
Guanghua Yu 已提交
18 19 20 21 22
Running PP-PicoDet object detection model on bare metal Arm(R) Cortex(R)-M55 CPU using Arm Virtual Hardware
======================================================================

This folder contains an example of how to run a PP-PicoDet model on bare metal [Cortex(R)-M55 CPU](https://www.arm.com/products/silicon-ip-cpu/cortex-m/cortex-m55) using [Arm Virtual Hardware](https://www.arm.com/products/development-tools/simulation/virtual-hardware).

G
Guanghua Yu 已提交
23

G
Guanghua Yu 已提交
24
Running environment and prerequisites
G
Guanghua Yu 已提交
25
-------------
G
Guanghua Yu 已提交
26 27
Case 1: If the demo is run in Arm Virtual Hardware Amazon Machine Image(AMI) instance hosted by [AWS](https://aws.amazon.com/marketplace/pp/prodview-urbpq7yo5va7g?sr=0-1&ref_=beagle&applicationId=AWSMPContessa)/[AWS China](https://awsmarketplace.amazonaws.cn/marketplace/pp/prodview-2y7nefntbmybu), the following software will be installed through [configure_avh.sh](./configure_avh.sh) script. It will install automatically when you run the application through [run_demo.sh](./run_demo.sh) script.
You can refer to this [guide](https://arm-software.github.io/AVH/main/examples/html/MicroSpeech.html#amilaunch) to launch an Arm Virtual Hardware AMI instance.
G
Guanghua Yu 已提交
28

G
Guanghua Yu 已提交
29 30 31
Case 2: If the demo is run in the [ci_cpu Docker container](https://github.com/apache/tvm/blob/main/docker/Dockerfile.ci_cpu) provided with [TVM](https://github.com/apache/tvm), then the following software will already be installed.

Case 3: If the demo is not run in the ci_cpu Docker container, then you will need the following:
G
Guanghua Yu 已提交
32 33
- Software required to build and run the demo (These can all be installed by running
  tvm/docker/install/ubuntu_install_ethosu_driver_stack.sh.)
34
  - [Fixed Virtual Platform (FVP) based on Arm(R) Corstone(TM)-300 software](https://release/2.5er.arm.com/tools-and-software/open-source-software/arm-platforms-software/arm-ecosystem-fvps)
G
Guanghua Yu 已提交
35
  - [cmake 3.19.5](https://github.com/Kitware/CMake/releases/)
36
  - [GCC toolchain from Arm(R)](https://release/2.5er.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2)
G
Guanghua Yu 已提交
37 38 39 40 41 42 43 44
  - [Arm(R) Ethos(TM)-U NPU driver stack](https://review.mlplatform.org)
  - [CMSIS](https://github.com/ARM-software/CMSIS_5)
- The python libraries listed in the requirements.txt of this directory
  - These can be installed by running the following from the current directory:
    ```bash
    pip install -r ./requirements.txt
    ```

G
Guanghua Yu 已提交
45 46 47 48 49 50 51 52
In case2 and case3:  

You will need to update your PATH environment variable to include the path to cmake 3.19.5 and the FVP.
For example if you've installed these in ```/opt/arm``` , then you would do the following:
```bash
export PATH=/opt/arm/FVP_Corstone_SSE-300/models/Linux64_GCC-6.4:/opt/arm/cmake/bin:$PATH
```

G
Guanghua Yu 已提交
53
You will also need TVM which can either be:
G
Guanghua Yu 已提交
54
  - Installed from TLCPack(see [TLCPack](https://tlcpack.ai/))
G
Guanghua Yu 已提交
55 56 57 58 59 60 61 62 63 64
  - Built from source (see [Install from Source](https://tvm.apache.org/docs/install/from_source.html))
    - When building from source, the following need to be set in config.cmake:
      - set(USE_CMSISNN ON)
      - set(USE_MICRO ON)
      - set(USE_LLVM ON)


Running the demo application
----------------------------
Type the following command to run the bare metal text recognition application ([src/demo_bare_metal.c](./src/demo_bare_metal.c)):
G
Guanghua Yu 已提交
65

G
Guanghua Yu 已提交
66 67 68
```bash
./run_demo.sh
```
G
Guanghua Yu 已提交
69 70 71 72 73 74 75

If you are not able to use Arm Virtual Hardware Amazon Machine Image(AMI) instance hosted by AWS/AWS China, specify argument --enable_FVP to 1 to make the application run on local Fixed Virtual Platforms (FVPs) executables.

```bash
./run_demo.sh --enable_FVP 1
```

G
Guanghua Yu 已提交
76 77 78 79 80 81 82 83
If the Ethos(TM)-U platform and/or CMSIS have not been installed in /opt/arm/ethosu then
the locations for these can be specified as arguments to run_demo.sh, for example:

```bash
./run_demo.sh --cmsis_path /home/tvm-user/cmsis \
--ethosu_platform_path /home/tvm-user/ethosu/core_platform
```

G
Guanghua Yu 已提交
84 85 86
With [run_demo.sh](./run_demo.sh) to run the demo application, it will:
- Set up running environment by installing the required prerequisites automatically if running in Arm Virtual Hardware Amazon AMI instance(not specify --enable_FVP to 1)
- Download a PP-PicoDet model
G
Guanghua Yu 已提交
87 88 89 90
- Use tvmc to compile the text recognition model for Cortex(R)-M55 CPU and CMSIS-NN
- Create a C header file inputs.c containing the image data as a C array
- Create a C header file outputs.c containing a C array where the output of inference will be stored
- Build the demo application
G
Guanghua Yu 已提交
91
- Run the demo application on a Arm Virtual Hardware based on Arm(R) Corstone(TM)-300 software
G
Guanghua Yu 已提交
92 93 94 95 96 97 98 99 100 101
- The application will report the text on the image and the corresponding score.

Using your own image
--------------------
The create_image.py script takes a single argument on the command line which is the path of the
image to be converted into an array of bytes for consumption by the model.

The demo can be modified to use an image of your choice by changing the following line in run_demo.sh

```bash
G
Guanghua Yu 已提交
102
python3 ./convert_image.py path/to/image
G
Guanghua Yu 已提交
103 104 105 106
```

Model description
-----------------
G
Guanghua Yu 已提交
107
In this demo, the model we used is based on [PP-PicoDet](https://github.com/PaddlePaddle/PaddleDetection/tree/release/2.5/configs/picodet). Because of the excellent performance, PP-PicoDet are very suitable for deployment on mobile or CPU. And it is released by [PaddleDetection](https://github.com/PaddlePaddle/PaddleDetection).