Skip to content

Commit 791eada

Browse files
authored
Add files via upload
1 parent f96b24b commit 791eada

File tree

6 files changed

+1729
-0
lines changed

6 files changed

+1729
-0
lines changed

pipeline_deploy/edge_deploy.en.md

Lines changed: 321 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,321 @@
1+
---
2+
comments: true
3+
---
4+
5+
# PaddleX Edge Deployment Demo Usage Guide
6+
7+
- [PaddleX Edge Deployment Demo Usage Guide](#paddlex-edge-deployment-demo-usage-guide)
8+
- [Installation Process and Usage](#installation-process-and-usage)
9+
- [Environment Preparation](#environment-preparation)
10+
- [Material Preparation](#material-preparation)
11+
- [Deployment Steps](#deployment-steps)
12+
- [Reference Materials](#reference-materials)
13+
- [Feedback Section](#feedback-section)
14+
15+
This guide mainly introduces the operation method of the PaddleX edge deployment demo on the Android shell.
16+
This guide applies to 8 models across 6 modules:
17+
18+
<table>
19+
<tr>
20+
<th>Module</th>
21+
<th>Specific Model</th>
22+
<th>CPU</th>
23+
<th>GPU</th>
24+
</tr>
25+
<tr>
26+
<td rowspan="2">Object Detection</td>
27+
<td>PicoDet-S</td>
28+
<td>✅</td>
29+
<td>✅</td>
30+
</tr>
31+
<tr>
32+
<td>PicoDet-L</td>
33+
<td>✅</td>
34+
<td>✅</td>
35+
</tr>
36+
<tr>
37+
<td>Layout Area Detection</td>
38+
<td>PicoDet_layout_1x</td>
39+
<td>✅</td>
40+
<td>✅</td>
41+
</tr>
42+
<tr>
43+
<td>Semantic Segmentation</td>
44+
<td>PP-LiteSeg-T</td>
45+
<td>✅</td>
46+
<td>✅</td>
47+
</tr>
48+
<tr>
49+
<td rowspan="2">Image Classification</td>
50+
<td>PP-LCNet_x1_0</td>
51+
<td>✅</td>
52+
<td>✅</td>
53+
</tr>
54+
<tr>
55+
<td>MobileNetV3_small_x1_0</td>
56+
<td>✅</td>
57+
<td>✅</td>
58+
</tr>
59+
<tr>
60+
<td>Text Detection</td>
61+
<td>PP-OCRv4_mobile_det</td>
62+
<td>✅</td>
63+
<td></td>
64+
</tr>
65+
<tr>
66+
<td>Text Recognition</td>
67+
<td>PP-OCRv4_mobile_rec</td>
68+
<td>✅</td>
69+
<td></td>
70+
</tr>
71+
</table>
72+
73+
<b>Note</b>
74+
- `GPU` refers to [mapping computations to GPU execution using OpenCL](https://www.paddlepaddle.org.cn/lite/develop/demo_guides/opencl.html) to fully utilize GPU hardware computing power and improve inference performance.
75+
76+
## Installation Process and Usage
77+
78+
### Environment Preparation
79+
80+
1. Install CMake build tool locally and download the required version of NDK software package from the [Android NDK official website](https://developer.android.google.cn/ndk/downloads?hl=en). For example, if developing on a Mac, download the NDK software package for the Mac platform from the Android NDK official website.
81+
82+
<b>Environment Requirements</b>
83+
- `CMake >= 3.10` (Minimum version not verified, recommend 3.20 and above)
84+
- `Android NDK >= r17c` (Minimum version not verified, recommend r20b and above)
85+
86+
<b>Tested Environment Used in This Guide</b>:
87+
- `cmake == 3.20.0`
88+
- `android-ndk == r20b`
89+
90+
2. Prepare an Android phone and enable USB debugging mode. Enable method: `Phone Settings -> Locate Developer Options -> Turn on Developer Options and USB Debugging Mode`.
91+
92+
3. Install ADB tool on your computer for debugging. ADB installation methods:
93+
94+
3.1. For Mac:
95+
96+
```shell
97+
brew cask install android-platform-tools
98+
```
99+
100+
3.2. For Linux:
101+
102+
```shell
103+
# Debian-based Linux distributions
104+
sudo apt update
105+
sudo apt install -y wget adb
106+
107+
# Red Hat-based Linux distributions
108+
sudo yum install adb
109+
```
110+
111+
3.3. For Windows:
112+
113+
Install ADB by downloading the ADB software package from Google's Android platform: [Link](https://developer.android.com/studio?hl=en)
114+
115+
Open a terminal, connect your phone to the computer, and enter in the terminal:
116+
117+
```shell
118+
adb devices
119+
```
120+
121+
If there is an output from the device, it indicates that the installation was successful.
122+
123+
```shell
124+
List of devices attached
125+
744be294 device
126+
```
127+
128+
### Material Preparation
129+
130+
1. Clone the `feature/paddle-x` branch of the `Paddle-Lite-Demo` repository into the `PaddleX-Lite-Deploy` directory.
131+
132+
```shell
133+
git clone -b feature/paddle-x https://github.com/PaddlePaddle/Paddle-Lite-Demo.git PaddleX-Lite-Deploy
134+
```
135+
136+
2. Fill out the <b>survey</b> to download the compressed package, place the compressed package in the specified unzip directory, switch to the specified unzip directory, and execute the unzip command.
137+
- [Object Detection Survey](https://paddle.wjx.cn/vm/OjV8gAb.aspx#)
138+
- [Semantic Segmentation Survey](https://paddle.wjx.cn/vm/Q2F1L37.aspx#)
139+
- [Image Classification Survey](https://paddle.wjx.cn/vm/rWPncBm.aspx#)
140+
- [OCR Survey](https://paddle.wjx.cn/vm/eaaBo0H.aspx#)
141+
142+
Below is an example of the unzip operation for object_detection. Refer to the table below for other pipelines.
143+
144+
```shell
145+
# 1. Switch to the specified unzip directory
146+
cd PaddleX-Lite-Deploy/object_detection/android/shell/cxx/picodet_detection
147+
148+
# 2. Execute the unzip command
149+
unzip object_detection.zip
150+
```
151+
152+
<table>
153+
<tr>
154+
<th>Pipeline Name</th>
155+
<th>Unzip Directory</th>
156+
<th>Unzip Command</th>
157+
</tr>
158+
<tr>
159+
<td>Object Detection</td>
160+
<td>PaddleX-Lite-Deploy/object_detection/android/shell/cxx/picodet_detection</td>
161+
<td>unzip object_detection.zip</td>
162+
</tr>
163+
<tr>
164+
<td>Semantic Segmentation</td>
165+
<td>PaddleX-Lite-Deploy/semantic_segmentation/android/shell/cxx/semantic_segmentation</td>
166+
<td>unzip semantic_segmentation.zip</td>
167+
</tr>
168+
<tr>
169+
<td>Image Classification</td>
170+
<td>PaddleX-Lite-Deploy/image_classification/android/shell/cxx/image_classification</td>
171+
<td>unzip image_classification.zip</td>
172+
</tr>
173+
<tr>
174+
<td>OCR</td>
175+
<td>PaddleX-Lite-Deploy/ocr/android/shell/ppocr_demo</td>
176+
<td>unzip ocr.zip</td>
177+
</tr>
178+
</table>
179+
180+
### Deployment Steps
181+
182+
1. Switch the working directory to `PaddleX_Lite_Deploy/libs` and run the `download.sh` script to download the necessary Paddle Lite prediction library. This step only needs to be executed once to support each demo.
183+
184+
2. Switch the working directory to `PaddleX_Lite_Deploy/{Task_Name}/assets`, run the `download.sh` script to download the [paddle_lite_opt tool](https://www.paddlepaddle.org.cn/lite/v2.10/user_guides/model_optimize_tool.html) optimized model, test images, label files, etc.
185+
186+
3. Switch the working directory to `PaddleX_Lite_Deploy/{Task_Name}/android/shell/cxx/{Demo_Name}`, run the `build.sh` script to complete the compilation and execution of the executable file.
187+
188+
4. Switch the working directory to `PaddleX-Lite-Deploy/{Task_Name}/android/shell/cxx/{Demo_Name}`, run the `run.sh` script to complete the prediction on the edge.
189+
190+
<b>Note</b>:
191+
- `{Pipeline_Name}` and `{Demo_Name}` are placeholders. Refer to the table at the end of this section for specific values.
192+
- `download.sh` and `run.sh` support passing in model names to specify models. If not specified, the default model will be used. Refer to the `Model_Name` column in the table at the end of this section for currently supported models.
193+
- To use your own trained model, refer to the [Model Conversion Method](https://paddlepaddle.github.io/Paddle-Lite/develop/model_optimize_tool/) to obtain the `.nb` model, place it in the `PaddleX_Lite_Deploy/{Pipeline_Name}/assets/{Model_Name}` directory, where `{Model_Name}` is the model name, e.g., `PaddleX_Lite_Deploy/object_detection/assets/PicoDet-L`.
194+
- Before running the `build.sh` script, change the path specified by `NDK_ROOT` to the actual installed NDK path.
195+
- Keep ADB connected when running the `build.sh` script.
196+
- On Windows systems, you can use Git Bash to execute the deployment steps.
197+
- If compiling on a Windows system, set `CMAKE_SYSTEM_NAME` to `windows` in `CMakeLists.txt`.
198+
- If compiling on a Mac system, set `CMAKE_SYSTEM_NAME` to `darwin` in `CMakeLists.txt`.
199+
200+
Below is an example for object_detection. For other demos, change the directories switched in steps 2 and 3 according to the table at the end of this section.
201+
202+
```shell
203+
# 1. Download the necessary Paddle Lite prediction library
204+
cd PaddleX_Lite_Deploy/libs
205+
sh download.sh
206+
207+
# 2. Download the paddle_lite_opt tool optimized model, test images, and label files
208+
cd ../object_detection/assets
209+
sh download.sh
210+
# Supports passing in model names to specify the downloaded model. Refer to the Model_Name column in the table at the end of this section for supported models.
211+
# sh download.sh PicoDet-L
212+
213+
# 3. Complete the compilation of the executable file
214+
cd ../android/app/shell/cxx/picodet_detection
215+
sh build.sh
216+
217+
# 4. Prediction
218+
sh run.sh
219+
# Supports passing in model names to specify the prediction model. Refer to the Model_Name column in the table at the end of this section for supported models.
220+
# sh run.sh PicoDet-L
221+
```
222+
223+
The run results are shown below, and a result image named `dog_picodet_detection_result.jpg` is generated:
224+
225+
```text
226+
======= benchmark summary =======
227+
input_shape(s) (NCHW): {1, 3, 320, 320}
228+
model_dir:./models/PicoDet-S/model.nb
229+
warmup:1
230+
repeats:10
231+
power_mode:1
232+
thread_num:0
233+
<b>* time info(ms) </b>*
234+
1st_duration:320.086
235+
max_duration:277.331
236+
min_duration:272.67
237+
avg_duration:274.91
238+
239+
====== output summary ======
240+
detection, image size: 768, 576, detect object: bicycle, score: 0.905929, location: x=125, y=1
241+
```
242+
243+
<img src="https://github.com/PaddlePaddle/Paddle-Lite-Demo/blob/feature/paddle-x/docs_img/object_detection/PicoDet-S.jpg?raw=true">
244+
245+
This section describes the deployment steps applicable to the demos listed in the following table:
246+
247+
<table>
248+
<tr>
249+
<th>Pipeline</th>
250+
<th>Pipeline_Name</th>
251+
<th>Module</th>
252+
<th>Demo_Name</th>
253+
<th>Specific Model</th>
254+
<th>Model_Name</th>
255+
</tr>
256+
<tr>
257+
<td rowspan="3">General Object Detection</td>
258+
<td rowspan="3">object_detection</td>
259+
<td rowspan="3">Object Detection</td>
260+
<td rowspan="3">picodet_detection</td>
261+
<td>PicoDet-S</td>
262+
<td>PicoDet-S(default)</br>PicoDet-S_gpu</td>
263+
</tr>
264+
<tr>
265+
<td>PicoDet-L</td>
266+
<td>PicoDet-L</br>PicoDet-L_gpu</td>
267+
</tr>
268+
<tr>
269+
<td>PicoDet_layout_1x</td>
270+
<td>PicoDet_layout_1x</br>PicoDet_layout_1x_gpu</td>
271+
</tr>
272+
<tr>
273+
<td>General Semantic Segmentation</td>
274+
<td>semantic_segmentation</td>
275+
<td>Semantic Segmentation</td>
276+
<td>semantic_segmentation</td>
277+
<td>PP-LiteSeg-T</td>
278+
<td>PP-LiteSeg-T(default)</br>PP-LiteSeg-T_gpu</td>
279+
</tr>
280+
<tr>
281+
<td rowspan="2">General Image Classification</td>
282+
<td rowspan="2">image_classification</td>
283+
<td rowspan="2">Image Classification</td>
284+
<td rowspan="2">image_classification</td>
285+
<td>PP-LCNet_x1_0</td>
286+
<td>PP-LCNet_x1_0(default)</br>PP-LCNet_x1_0_gpu</td>
287+
</tr>
288+
<tr>
289+
<td>MobileNetV3_small_x1_0</td>
290+
<td>MobileNetV3_small_x1_0</br>MobileNetV3_small_x1_0_gpu</td>
291+
</tr>
292+
<tr>
293+
<td rowspan="2">General OCR</td>
294+
<td rowspan="2">ocr</td>
295+
<td>Text Detection</td>
296+
<td rowspan="2">ppocr_demo</td>
297+
<td>PP-OCRv4_mobile_det</td>
298+
<td>PP-OCRv4_mobile_det</td>
299+
</tr>
300+
<tr>
301+
<td>Text Recognition</td>
302+
<td>PP-OCRv4_mobile_rec</td>
303+
<td>PP-OCRv4_mobile_rec</td>
304+
</tr>
305+
</table>
306+
307+
<b>Note</b>
308+
- Currently, there is no demo for deploying the Layout Area Detection module on the edge, so the `picodet_detection` demo is reused to deploy the `PicoDet_layout_1x` model.
309+
310+
## Reference Materials
311+
312+
This guide only introduces the basic installation and usage process of the edge deployment demo. If you want to learn more detailed information, such as code introduction, code explanation, updating models, updating input and output preprocessing, updating prediction libraries, etc., please refer to the following documents:
313+
314+
- [Object Detection](https://github.com/PaddlePaddle/Paddle-Lite-Demo/tree/feature/paddle-x/object_detection/android/shell/cxx/picodet_detection)
315+
- [Semantic Segmentation](https://github.com/PaddlePaddle/Paddle-Lite-Demo/blob/feature/paddle-x/semantic_segmentation/android/shell/cxx/semantic_segmentation/README.md)
316+
- [Image Classification](https://github.com/PaddlePaddle/Paddle-Lite-Demo/blob/feature/paddle-x/image_classification/android/shell/cxx/image_classification/README.md)
317+
- [OCR](https://github.com/PaddlePaddle/Paddle-Lite-Demo/blob/feature/paddle-x/ocr/android/shell/ppocr_demo/README.md)
318+
319+
## Feedback Section
320+
321+
The edge deployment capabilities are continuously optimized. Welcome to submit [issue](https://github.com/PaddlePaddle/PaddleX/issues/new/choose) to report problems and needs, and we will follow up promptly.

0 commit comments

Comments
 (0)