From 7a9c8af11d38bb246a9be048219d8574abb3b0de Mon Sep 17 00:00:00 2001 From: Liliya WU Date: Thu, 30 Jun 2022 13:39:21 +0800 Subject: [PATCH] update scripts to run in cloud-based avh --- deploy/avh/README.md | 50 ++++++++++++++--------- deploy/avh/configure_avh.sh | 79 +++++++++++++++++++++++++++++++++++++ deploy/avh/run_demo.sh | 53 ++++++++++++++++++++----- 3 files changed, 153 insertions(+), 29 deletions(-) create mode 100755 deploy/avh/configure_avh.sh diff --git a/deploy/avh/README.md b/deploy/avh/README.md index 922fb4da..a64bfd3a 100644 --- a/deploy/avh/README.md +++ b/deploy/avh/README.md @@ -15,20 +15,22 @@ -Running PaddleOCR text recognition model via TVM on bare metal Arm(R) Cortex(R)-M55 CPU and CMSIS-NN -=============================================================== +Running PaddleOCR text recognition model on bare metal Arm(R) Cortex(R)-M55 CPU using Arm Virtual Hardware +====================================================================== -This folder contains an example of how to use TVM to run a PaddleOCR model -on bare metal Cortex(R)-M55 CPU and CMSIS-NN. +This folder contains an example of how to run a PaddleOCR 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). -Prerequisites + +Running environment and prerequisites ------------- -If the demo is run in the ci_cpu Docker container provided with TVM, then the following -software will already be installed. +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. + +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. -If the demo is not run in the ci_cpu Docker container, then you will need the following: +Case 3: If the demo is not run in the ci_cpu Docker container, then you will need the following: - Software required to build and run the demo (These can all be installed by running - https://github.com/apache/tvm/blob/main/docker/install/ubuntu_install_ethosu_driver_stack.sh .) + tvm/docker/install/ubuntu_install_ethosu_driver_stack.sh.) - [Fixed Virtual Platform (FVP) based on Arm(R) Corstone(TM)-300 software](https://developer.arm.com/tools-and-software/open-source-software/arm-platforms-software/arm-ecosystem-fvps) - [cmake 3.19.5](https://github.com/Kitware/CMake/releases/) - [GCC toolchain from Arm(R)](https://developer.arm.com/-/media/Files/downloads/gnu-rm/10-2020q4/gcc-arm-none-eabi-10-2020-q4-major-x86_64-linux.tar.bz2) @@ -40,19 +42,22 @@ If the demo is not run in the ci_cpu Docker container, then you will need the fo pip install -r ./requirements.txt ``` +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 +``` + You will also need TVM which can either be: + - Installed from TLCPack(see [TLCPack](https://tlcpack.ai/)) - 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) - - Installed from TLCPack nightly(see [TLCPack](https://tlcpack.ai/)) -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 -``` Running the demo application ---------------------------- @@ -62,6 +67,12 @@ Type the following command to run the bare metal text recognition application ([ ./run_demo.sh ``` +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 +``` + 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: @@ -70,13 +81,14 @@ the locations for these can be specified as arguments to run_demo.sh, for exampl --ethosu_platform_path /home/tvm-user/ethosu/core_platform ``` -This will: +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 PaddleOCR text recognition model - 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 -- Run the demo application on a Fixed Virtual Platform (FVP) based on Arm(R) Corstone(TM)-300 software +- Run the demo application on a Arm Virtual Hardware based on Arm(R) Corstone(TM)-300 software - The application will report the text on the image and the corresponding score. Using your own image @@ -92,9 +104,9 @@ python3 ./convert_image.py path/to/image Model description ----------------- -In this demo, the model we use is an English recognition model based on [PP-OCRv3](https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/doc/doc_ch/PP-OCRv3_introduction.md). PP-OCRv3 is the third version of the PP-OCR series model released by [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR). This series of models has the following features: +The example is built on [PP-OCRv3](https://github.com/PaddlePaddle/PaddleOCR/blob/dygraph/doc/doc_ch/PP-OCRv3_introduction.md) English recognition model released by [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR). PP-OCRv3 is the third version of the PP-OCR series model. This series of models has the following features: - PP-OCRv3: ultra-lightweight OCR system: detection (3.6M) + direction classifier (1.4M) + recognition (12M) = 17.0M - Support more than 80 kinds of multi-language recognition models, including English, Chinese, French, German, Arabic, Korean, Japanese and so on. For details - Support vertical text recognition, and long text recognition -The text recognition model in PP-OCRv3 supports more than 80 languages. In the process of model development, since Arm(R) Cortex(R)-M55 CPU does not support rnn operator, we delete the unsupported operator based on the PP-OCRv3 text recognition model to obtain the current model. \ No newline at end of file +The text recognition model in PP-OCRv3 supports more than 80 languages. In the process of model development, since Arm(R) Cortex(R)-M55 CPU does not support rnn operator, we delete the unsupported operator based on the PP-OCRv3 text recognition model to obtain the current model. diff --git a/deploy/avh/configure_avh.sh b/deploy/avh/configure_avh.sh new file mode 100755 index 00000000..8042fd81 --- /dev/null +++ b/deploy/avh/configure_avh.sh @@ -0,0 +1,79 @@ +#!/bin/bash +# Copyright (c) 2022 Arm Limited and Contributors. All rights reserved. +# 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 +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# 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. + +set -e +set -u +set -o pipefail + +# Show usage +function show_usage() { + cat <&2 + show_usage >&2 + exit 1 + fi + ;; -*|--*) echo "Error: Unknown flag: $1" >&2 @@ -100,17 +123,27 @@ while (( $# )); do esac done +# Choose running environment: cloud(default) or local environment +Platform="VHT_Corstone_SSE-300_Ethos-U55" +if [ $FVP_enable == "1" ]; then + Platform="FVP_Corstone_SSE-300_Ethos-U55" + echo -e "\e[36mRun application on local Fixed Virtual Platforms (FVPs)\e[0m" +else + if [ ! -d "/opt/arm/" ]; then + sudo ./configure_avh.sh + fi +fi # Directories script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" - # Make build directory -rm -rf build make cleanall mkdir -p build cd build +# Get PaddlePaddle inference model +echo -e "\e[36mDownload PaddlePaddle inference model\e[0m" wget https://paddleocr.bj.bcebos.com/tvm/ocr_en.tar tar -xf ocr_en.tar @@ -144,9 +177,9 @@ cd ${script_dir} echo ${script_dir} make -# Run demo executable on the FVP -FVP_Corstone_SSE-300_Ethos-U55 -C cpu0.CFGDTCMSZ=15 \ +# Run demo executable on the AVH +$Platform -C cpu0.CFGDTCMSZ=15 \ -C cpu0.CFGITCMSZ=15 -C mps3_board.uart0.out_file=\"-\" -C mps3_board.uart0.shutdown_tag=\"EXITTHESIM\" \ -C mps3_board.visualisation.disable-visualisation=1 -C mps3_board.telnetterminal0.start_telnet=0 \ -C mps3_board.telnetterminal1.start_telnet=0 -C mps3_board.telnetterminal2.start_telnet=0 -C mps3_board.telnetterminal5.start_telnet=0 \ -./build/demo \ No newline at end of file +./build/demo --stat -- GitLab