Skip to content

Commit 158ea68

Browse files
committed
Add Mnist on SBC
1 parent bf5f437 commit 158ea68

File tree

3 files changed

+160
-0
lines changed

3 files changed

+160
-0
lines changed

SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
* [Nvidia Cuda](develop/device/cuda.md)
3030
* [案例](solution/solution.md)
3131
* [车辆检测](solution/car-detect.md)
32+
* [树莓派开发板Mnist识别](solution/mnist-on-sbc.md)
3233
* [基本概念](framework-conception/framework-conception.md)
3334
* [](framework-conception/graph.md)
3435
* [功能单元](framework-conception/flowunit.md)

solution/mnist-on-sbc.md

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# 树莓派开发板中运行mnist手写体识别
2+
3+
Modelbox支持当前主流的几种开发板,比如树莓派4,RK3399,RK3568芯片的Linux系统。
4+
本文介绍了,使用已有操作系统,如何从构建ModelBox开始,到训练生成模型,然后在进行推理的全流程。
5+
6+
mnist为一个REST-API服务,通过REST请求,发送base64的手写图片进行推理,REST-API给出推理结果。
7+
关于ModelBox中Mnist代码实现,可以先参考[第一个应用](../develop/first-app/first-app.md)
8+
9+
## 编译环境准备
10+
11+
### 安装依赖的开发库
12+
13+
```shell
14+
apt-get update
15+
apt-get -y install cmake git wget build-essential npm curl \
16+
python3 python3-pip python-is-python3 \
17+
libssl-dev libcpprest-dev libopencv-dev libgraphviz-dev python3-dev \
18+
libavfilter-dev libavdevice-dev libavcodec-dev
19+
pip install requests opencv-python
20+
21+
```
22+
23+
如上述依赖安装比较慢,可以使用国内的镜像进行安装,具体镜像如下:
24+
25+
* pip镜像下载:
26+
27+
配置参考:
28+
29+
<https://mirrors.tuna.tsinghua.edu.cn/help/pypi/>
30+
31+
临时使用参考:
32+
33+
```shell
34+
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests opencv-python
35+
```
36+
37+
* apt镜像下载:
38+
39+
配置参考:
40+
41+
<https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu/>
42+
<https://mirrors.tuna.tsinghua.edu.cn/help/debian/>
43+
44+
* npm镜像:
45+
46+
配置参考:
47+
48+
```shell
49+
npm config set registry https://registry.npmmirror.com
50+
```
51+
52+
### 下载安装MindSpore-Lite推理引擎
53+
54+
下载aarch64的MindSporeLite:
55+
56+
```shell
57+
wget https://ms-release.obs.cn-north-4.myhuaweicloud.com/1.7.0/MindSpore/lite/release/linux/aarch64/mindspore-lite-1.7.0-linux-aarch64.tar.gz
58+
tar xf mindspore-lite-1.7.0-linux-aarch64.tar.gz
59+
mv mindspore-lite-1.7.0-linux-aarch64 /usr/local/
60+
ln -s /usr/local/mindspore-lite-1.7.0-linux-aarch64 /usr/local/mindspore-lite
61+
62+
```
63+
64+
其他版本下载地址: <https://www.mindspore.cn/lite>
65+
66+
## 编译ModelBox
67+
68+
1. 下载并编译ModelBox
69+
70+
主站:
71+
72+
```shell
73+
git clone https://github.com/modelbox-ai/modelbox.git
74+
```
75+
76+
国内镜像:
77+
78+
```shell
79+
git clone https://gitee.com/modelbox/modelbox.git
80+
```
81+
82+
1. 编译ModelBox:
83+
84+
```shell
85+
cd modelbox
86+
mkdir build
87+
cd build
88+
cmake .. -DCMAKE_BUILD_TYPE=Debug
89+
make package -j4
90+
```
91+
92+
如果下载慢,可以切换使用国内镜像:
93+
94+
```shell
95+
cmake .. -DCMAKE_BUILD_TYPE=Debug -DUSE_CN_MIRROR=yes
96+
```
97+
98+
1. 安装ModelBox
99+
100+
```shell
101+
dpkg -i release/*.deb
102+
```
103+
104+
## 使用ModelBox编排开发
105+
106+
1. 启动ModelBox编排开发服务
107+
108+
```shell
109+
modelbox-tool develop -s
110+
```
111+
112+
1. 链接ModelBox编排服务
113+
114+
服务启动后,可以直接链接编排服务,服务启动的信息,可以通过如下命令查询:
115+
116+
```shell
117+
modelbox-tool develop -q
118+
```
119+
120+
浏览器访问上述地址的1104端口
121+
注意事项:
122+
* 如有权限问题,修改conf/modelbox.conf配置文件中的acl.allow数组,增加允许访问的IP范围。
123+
* 推荐使用vscode的远程链接的终端操作,vscode可以自动建立端口转发。[远程开发](https://code.visualstudio.com/docs/remote/ssh)
124+
125+
1. 新建mnist服务
126+
127+
* 点击任务编排
128+
* 点击项目->新建项目,
129+
* 新建项目:
130+
* 输入创建项目的名称:`mnist`
131+
* 路径: `/home/[user]`
132+
* 项目模板为: `mnist-mindspore`
133+
134+
1. 训练模型
135+
136+
* 使用如下shell命令执行训练:
137+
138+
```shell
139+
cd ~/mnist/src/flowunit/mnist_infer
140+
chmod +x train.sh
141+
./train.sh
142+
```
143+
144+
1. 启动mnist服务
145+
146+
浏览器打开编排界面,打开mnist项目,点击项目上`启动`按钮mnist服务。
147+
148+
注意:
149+
* 若启动失败,请根据界面的提示进行处理。
150+
151+
1. 推理验证:
152+
153+
* 使用如下命令进行内置的推理验证
154+
155+
```shell
156+
cd ~/mnist/src/graph
157+
python test_mnist.py
158+
```

solution/solution.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ ModelBox同时也提供了一些推理的案例
55
| 案例名称 | 案例图例 | 案例链接 |
66
| :------: | :------------------------------------------------------------: | :-----------------------------: |
77
| 车辆检测 | ![car-detect](../assets/images/figure/solution/car-detect.png) | [车辆检测案例](./car-detect.md) |
8+
| 树莓派开发板Mnist识别 | | [Mnist手写体识别](mnist-on-sbc.md) |

0 commit comments

Comments
 (0)