请选择 进入手机版 | 继续访问电脑版

你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

基于STM32F767ZI AI 应用工程创建----转载  

[复制链接]
木木&点点 发布时间:2019-1-6 17:29
偶然看到一篇好文章,分享给大家。
2 ]8 _8 e1 t" W- [9 P; _
9 P+ e: J' k0 f9 Y# x, D* a
1.jpg

9 V8 C/ \. u  g" _6 T
今天介绍下ST官方刚刚推出的CubeMx 自带的X-CUBE-AI(Artificial intelligent)插件功能,可以给现有的STM32 M3-M7高性能的处理器添加基于训练好的ANN 的模型用于不同的数据分析处理。

4 N' S# Z3 p$ J1 \5 @/ X
使用STM32Cube.AI简化了人工神经网络映射

( s2 p0 t( }  C+ r$ m6 e# M
1.可与流行的深度学习培训工具互操作
2.兼容许多IDE和编译器
3.传感器和RTOS无关
4.允许多个人工神经网络在单个STM32MCU上运行
5.完全支持超低功耗STM32MCU

. f& @7 d2 K3 v+ Y  }
提高您的工作效率
. R: g$ {2 D5 T2 E: ~* d
利用DeepLearning的强大功能提高信号处理性能并提高STM32应用程序的生产率。创建人工神经网络并将其映射到STM32(通过CubeMx自动生成优化的代码),而无需手动构建代码。
以上就做个简短的介绍,想了解更多有关STM32Cube.AI可以访问下面的链接:http://www.st.com/content/st_com ... 2_gl_social_dec2018

8 X( ~2 P% q* x% ]
那先前的准备工作就是需要安装最新版本的CubeMx 5.0.1
然后使用CubeMx 去安装X-CUBE-AI插件, 700多M的容量。。慢慢下载吧

7 w& E3 O1 E0 n2 B
2.jpg
! n* b5 M5 o/ H+ R# k
下载好后,CubeMx里的Artificial intelligent
激活Enable

! }) M& o8 E0 W; [6 {3 b
3.jpg
: n9 Y1 g7 f- M( ~% K# L
这里我们就可以看到里面的选项了
下载下来。。然后选择Keras 的AI API算法
6 }/ z6 o' @! W
4.jpg
8 l$ m  f5 h8 d: B4 l& ^$ h
model.h5就是我们需要导入到工程里的AI Keras的训练好的模型
4 U* ~  o7 d3 A! L6 D
5.jpg

9 r% [1 |/ d' ^2 t( N: F
Human Activity Recognition Using Convolutional Neural Network in Keras
人类活动识别卷积神经网络算法模型
6.jpg

0 Z% X/ O9 M0 c3 x% l$ B7 n. s
然后我们导入到工程里
7.jpg

- J1 ?$ Z# Z/ v
这里选择压缩参数,不同的压缩参数对MCU的flash容量
要求也不一样。。
8.jpg
4 D0 {3 w  M3 b
点击Analyze cube就好计算使用这个神经网络算法的ram和flash容量占用
, A% J9 z) d/ D+ I/ [$ V+ {/ Q4 m1 {
9.jpg
. I4 d- f  ^* x7 S2 @, }6 I, x
好了结果出来了,

8 N6 d0 p0 F/ T4 x
10.jpg
; b: A/ A! W3 v1 a/ ^9 \
经过分析后Cube会自动列出可以使用的MCU
然后显示在列表里
11.jpg

  J4 C1 B' g# M) |  p, O. I# i
这里举个例子,我们选择没有压缩优化
分析模型算法后的结果我没有匹配的MCU可以使用

+ U! _% w" Q. |1 G! ^
12.jpg

9 G# D& E" c; ~2 t8 u4 y$ t" l
这是选择压缩比参数8的结果,可以支持很多的MCU使用这个神经网络算法。。

2 e# X$ w5 Y0 S/ C8 p
13.jpg
% p. \6 T0 z3 l( p; O1 t# o( s/ \
好了,这里我们就选择STM32F767ZI Nucleo 板卡作为 这次演示使用的板卡
% _. c8 x* R7 U3 {$ s
14.jpg
好了选择好了,板卡,我们还需要给它添加扩展库,也就是AI库; b2 y) Q4 y. E6 J/ h. _
! E7 J  T: `0 S
15.jpg

* L4 D) G0 h4 }$ B, f9 B# E  q( h8 w5 t6 g. V5 x3 W* G! ^/ F
选择好Validation 和打勾 AI core

" v: b  p4 F6 y& u# j" Q! u/ c& O
16.jpg

8 U, v* j2 w! Y( L$ v# a3 \
然后在cube 左下方可以看到下图箭头 提示的插件功能

" T" [: p1 L7 j$ {2 R# L4 `# I
17.jpg
9 A2 x. k3 ~' y: N
我们需要打勾以下2个功能
, Y6 f# p" j; M7 n
18.jpg

' q; t; z7 ?8 }; y! Z) Q/ P
然后创建我的AI算法名称,这个名称会在后续的里自动创建好。

& h) \7 L- G* `+ G' ?
19.jpg
% Z8 `+ X) ^; C6 a$ i- s& G
添加好,我们下载好的AI神经网络算法,然后再Analyze下就好。。打勾表示验证通过

" ^- Z2 e' `  S" F) l) G7 s
20.jpg
7 K1 `2 C) ~" E. V' k- k
然后我们需要配置我们的mcu的 CPU ICache 和 CPU DCache

. z) G% M# n  Y5 w
21.jpg

. s' W' S' `0 }
然后配置MCU主频为216Mhz

" X( p! `& c( z& S4 O) r
22.jpg

4 V# A- p6 t. Q( G3 {
1 v" `  w# a) J7 }' V
然后我们需要配置串口3和CubeMx进行通讯,验证我们工程。。。

2 A9 M0 ^( z$ j( [$ _; Q  O" s
23.jpg

( W. |- B7 X( S/ t3 n
然后在 AI扩展功能里选择通讯端口为串口3
2 [0 {* e" g  a4 m
24.jpg
好了,工程差不多创建好了。接下来就是 配置工程的路径好 我们配置使用IAR 编译环境。。 然后Heap 然后要配置到2000 这个很重要,要是设置少了 系统就会奔溃(切记)2 j1 l8 Y5 O1 j9 r* C- z8 M
; X+ P$ ^" x4 ]; t
25.jpg

/ l2 B  A3 u: \; W5 n
好了工程生成好了,我们就可以 使用IAR 打开工程了 工程如下,工程里自动生成了基于AI的算法的所以文件
. p% I( k8 J% z# V% F
26.jpg

! A$ y1 N- \* @
这里可以看到,基于AI训练好的模型数据列表。。。
6 M/ c. c! |& b+ m0 a! K8 S
27.jpg
- k' t& I& \. ]
好了,配置位STLINK,然后编译好就可以直接下载到板子上了

4 T: J' J) F$ p% w; n1 e; K
28.jpg

4 O: g5 L3 q) X$ n& u* ?8 e" _
29.jpg
好了,现在我们需要回到CubeMx里,回到 AI扩展功能里。。 先重启下开发板,然后 点击Validation on target
# _( i: [# y# [9 I, j' B

* ]3 X3 P$ [7 H* G- W, `
30.jpg

7 Q3 n1 Y, E) u; }1 _
选择手动,然后选择对应的串口端口
6 e& S! I% ?& D" g# x: R3 R
31.jpg
' q5 F0 K8 [: x" w' M0 P
这里可以看到验证已经开始了‘

7 m; ]. Q9 B' S! R. G: f! |, g
32.jpg
好了,结果出来了。我们可以在串口输出的信息里看到有关的数据
# l5 L( ^( i2 W9 u' y
33.jpg

2 m/ k7 y0 R6 F. l: ^" {
34.jpg
35.jpg
. S0 G2 ^7 Y; Q8 E0 V8 z
36.jpg
: h; R& X9 T9 n2 D
/ {9 k) a. ~  t, v" _" P2 z
好了,基于CubeMx+AI扩展库的使用就分享到这了,想了解更多关于 使用STM32 AI的朋友可以关注ST官网的教程。。。
收藏 3 评论33 发布时间:2019-1-6 17:29

举报

33个回答
单片机爱好者 回答时间:2019-5-25 21:12:11
Build target 'STM32F767_AI'
$ V$ T1 A) ~$ b4 Sassembling startup_stm32f767xx.s...# i6 d6 q/ `4 f" E
compiling main.c...2 P1 Y! \$ B8 A1 z
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
, D% O0 K2 j; R1 \9 j3 P) C  #include "network.h"
! Q) O- V  }& u9 A5 f' ]- K/ [../Src/main.c: 0 warnings, 1 error
' T6 ]3 O0 A; F+ rcompiling app_x-cube-ai.c...
) v: a" h6 }+ j/ i& I5 V../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory+ u$ K, ~8 \3 `
  #include "network.h"
( s  I* D; y3 [* k- i../Src/app_x-cube-ai.c: 0 warnings, 1 error: i5 l( O9 j9 t6 G3 c6 y4 K: l
compiling stm32f7xx_it.c...
: O9 ^) Q" \0 u# F! \compiling stm32f7xx_hal_msp.c...
$ g6 G0 S, s$ u# F6 ocompiling stm32f7xx_hal_cortex.c...
1 s5 y6 }0 G7 l2 u6 B8 j  a8 pcompiling stm32f7xx_hal_crc.c...$ Z, F5 L2 ?2 Z
compiling stm32f7xx_hal_crc_ex.c...4 @- @5 A! W" M% _2 S2 }" F( d0 u
compiling stm32f7xx_hal_tim.c...! Z7 S, L+ U( B6 x2 r& A5 J& ^6 G3 C
compiling stm32f7xx_hal_tim_ex.c...
) L* X) F3 y2 ^2 F/ P; Tcompiling stm32f7xx_hal_uart.c...
. x) C( L9 h) ycompiling stm32f7xx_hal_uart_ex.c...% U' K  I, r( ^
compiling stm32f7xx_hal_rcc.c...! R) \, I  {5 G: H$ u, F! U0 H
compiling stm32f7xx_hal_rcc_ex.c...) n& L4 _$ t$ \2 k9 a$ \
compiling stm32f7xx_hal_flash.c...
# ?4 J0 n1 O) H& ?compiling stm32f7xx_hal_flash_ex.c...2 R' ^; N) {7 o1 z" T7 ?! v( y
compiling stm32f7xx_hal_gpio.c...- G8 m+ D& D1 R5 i8 `
compiling stm32f7xx_hal_dma.c...
& B' _2 D. z; R" w/ qcompiling stm32f7xx_hal_dma_ex.c...
& K! d; x6 B& ^compiling stm32f7xx_hal_pwr.c...
9 y+ n  j0 }4 o) {# s: Vcompiling stm32f7xx_hal_pwr_ex.c..." F6 m0 R5 p$ F  O9 E3 i
compiling stm32f7xx_hal.c...
' {& Z* r  h  O& P; x- X; \compiling stm32f7xx_hal_i2c.c...
' d/ Z; p3 L9 l" L' w2 t* v, gcompiling stm32f7xx_hal_i2c_ex.c...
$ O: G1 a/ M1 x# ycompiling stm32f7xx_hal_exti.c...) [3 _2 s5 v( m3 [8 o
compiling system_stm32f7xx.c...
9 |3 n3 n# e! B9 k2 A2 r. vcompiling aiPbMgr.c...! C6 t2 `' S: J3 g
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory% H1 p' Q! n" N! Z8 O
  #include "network.h"
+ Q- v4 \& I8 `& L../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiPbMgr.c: 0 warnings, 1 error
4 R5 n! ]+ C* H% H+ ^3 v9 [4 dcompiling aiTestUtility.c...2 r) Z- |3 d" A2 m
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory0 L( m2 u# B( x, E" M' Z
  #include "network.h"
" `  S, p" P# b' W../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiTestUtility.c: 0 warnings, 1 error6 p, n0 _8 k$ c$ n% x3 ?6 z
compiling aiValidation.c...& B1 |; z$ [: t& F8 {# R
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
% Z% F" s! p) k8 o9 v  #include "network.h"" h' u, z; s/ I' n
../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiValidation.c: 0 warnings, 1 error! z: t& d; m4 ]+ U- h" G, @
compiling pb_common.c...
+ E% N( M4 {0 ~7 D4 Dcompiling pb_decode.c...
2 P" g0 V* y+ ?; ccompiling pb_encode.c...
9 A/ U& A$ q2 w, L! Vcompiling stm32msg.pb.c...
+ s% Q# O: F/ @7 J, s4 @! P" c"STM32F767_AI\STM32F767_AI.axf" - 5 Error(s), 0 Warning(s).
+ Y+ c; ^' Z. X, x( _' A  LTarget not created.
单片机爱好者 回答时间:2019-5-25 21:11:53
Build target 'STM32F767_AI': u  r( }; H: }9 `
assembling startup_stm32f767xx.s...
! w" y8 W" m; U5 r( G0 W8 vcompiling main.c...; R) A8 _9 x* v5 i+ g$ D+ A
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
( J6 z" R- d) b7 u% L5 r  #include "network.h"2 @3 t+ v5 l. p. ~
../Src/main.c: 0 warnings, 1 error
/ o2 D+ x" e3 Jcompiling app_x-cube-ai.c...
" n6 H! E- ?; |" ]/ t( S../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
2 Y( H( K9 }8 h8 a# S5 _) G- K  #include "network.h"* Y) B- f: Q8 L  Z$ o2 Q( I
../Src/app_x-cube-ai.c: 0 warnings, 1 error  J) T. Z7 ?6 [. C
compiling stm32f7xx_it.c...: C6 h1 [) _7 _3 V- ?0 ]
compiling stm32f7xx_hal_msp.c...* T9 u1 h, N% }) ]( \' g' Z, f5 ?+ a
compiling stm32f7xx_hal_cortex.c...+ Q# O! z; z  r8 I, x
compiling stm32f7xx_hal_crc.c...
/ J# c1 }( q$ x7 r3 z, Vcompiling stm32f7xx_hal_crc_ex.c...$ @# |% ]4 m6 d
compiling stm32f7xx_hal_tim.c...
, k- k4 b0 v0 V3 m* Xcompiling stm32f7xx_hal_tim_ex.c...
* I2 R  n" K2 o7 a3 c4 r# dcompiling stm32f7xx_hal_uart.c..." ^* d& g( z7 v2 f* A( N
compiling stm32f7xx_hal_uart_ex.c...- I, `7 x9 @) Y4 j$ Y
compiling stm32f7xx_hal_rcc.c...1 E4 M: R' ~, S
compiling stm32f7xx_hal_rcc_ex.c.... ?/ u8 ?2 l/ d  v/ |& k
compiling stm32f7xx_hal_flash.c...8 I  Q* f; N' t8 Z  r2 w$ Y5 d; z+ U
compiling stm32f7xx_hal_flash_ex.c...! h3 v% s3 g- f/ t4 x( I3 A
compiling stm32f7xx_hal_gpio.c...
' |- ?* s9 {5 z3 d. Ccompiling stm32f7xx_hal_dma.c...
+ I3 D* H9 |) [  }2 Zcompiling stm32f7xx_hal_dma_ex.c...
* d+ h$ R" i2 t4 p) |compiling stm32f7xx_hal_pwr.c...! }) }+ c# f4 f
compiling stm32f7xx_hal_pwr_ex.c...8 }% T" j2 T5 L/ H, ?6 W
compiling stm32f7xx_hal.c...
4 B" G$ P% j0 x5 U' Dcompiling stm32f7xx_hal_i2c.c.... A, \  D* J0 m% T, o" x
compiling stm32f7xx_hal_i2c_ex.c...
1 M! I6 J% p& w! p" {) S% l& jcompiling stm32f7xx_hal_exti.c...# W, j4 a* u4 w  n
compiling system_stm32f7xx.c...' e: {$ }5 _9 y/ B, e5 ^- B2 n
compiling aiPbMgr.c...+ {  E, H  {. R) d% w/ V
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
1 H, _* F) u/ E) Z  #include "network.h"
1 {9 }8 l) I) ~" u6 l! O../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiPbMgr.c: 0 warnings, 1 error
. D& j* Q; Y: c" q4 I, b& qcompiling aiTestUtility.c...
; ^# _, p0 w4 h  @. a../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory4 G; z5 h* U/ Q/ v; c# N4 u
  #include "network.h") t! Y( m- \2 y) L8 n% u' U
../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiTestUtility.c: 0 warnings, 1 error
9 Z; `! c, g6 p# |4 _' o% Acompiling aiValidation.c...
7 v3 r" _& d5 ]; T../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
% u# I- y4 k0 c8 n8 j  #include "network.h") d+ u" Z( r2 E9 H" k6 W  d) u
../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiValidation.c: 0 warnings, 1 error/ @/ J8 B, j% Z( k8 @* x
compiling pb_common.c...
& \) q0 @0 R, y/ N+ Ccompiling pb_decode.c...$ X+ K3 L: d1 a. g5 d
compiling pb_encode.c...' y& W4 o1 E$ H/ `/ E! v: k
compiling stm32msg.pb.c...
0 ~4 @% ]6 U+ r. u) I"STM32F767_AI\STM32F767_AI.axf" - 5 Error(s), 0 Warning(s).
. W8 Z' R' t1 T8 R& ATarget not created.
Beatle 回答时间:2019-7-14 14:55:07
じ太阳当空照 发表于 2019-7-14 09:15  w/ S# Q8 b# o
我真的不知道是哪出了问题,求大神指导,我导入以后,选好芯片,然后点击Additional Software进去,里面 ...

& A8 O; ^7 u8 P1 W$ @  Y5 k首先确保已经安装了AI库
# R, e( F4 ?4 ^$ X, L7 Z. a! }% l
1.png / Z8 [% U- N( L% ]
使能Atificial intelligence后,配置好参数,确保自己使用的单片机是在列表中的。
, k1 ~+ `" `. Z) f2 ^0 @: ^
0 P0 P- l& ?  F) a0 _! t5 ?
1 [, S" p& q/ k( K! k: _ 2.png
, m1 }; O1 b/ d) o2 Y: Q, A3 V) F% W/ Z( |

9 q' |& S( w) q1 y
  J1 y- W+ ^) k8 ^' ^- s+ P如果确定上面操作无误,界面还是空的话那就看看这里的配置是否和你真实的路径是一致的。
- N0 k/ Z% k; |$ \
" }8 L2 x$ J) x: e  l/ @9 X1 u 3.png 4 c% A' }6 Y, H; ?! u5 t
zero99 回答时间:2019-1-8 13:15:38
看看
wujialing4000 回答时间:2019-1-8 15:24:33
辛苦了,学习了。耐心的看完每句话。
奏奏奏 回答时间:2019-1-8 19:12:17
用DSP部分来算神经网络,感觉是不是后面ST要出专用的神经网络计算单元了吗?
creep 回答时间:2019-1-9 09:44:21
厉害了@Paderboy
Paderboy 回答时间:2019-1-9 09:46:24
多谢分享。。
STMCU-管管 回答时间:2019-1-9 10:05:06
Paderboy 发表于 2019-1-9 09:469 j9 i/ l  o9 y
多谢分享。。
: w2 c! ^" y6 g: C( @
厉害了大佬
qhq8001 回答时间:2019-1-9 10:51:07
大概了解一下,感谢分享
xujiantj 回答时间:2019-1-10 09:06:19
谢谢楼主!!!
h55 回答时间:2019-1-21 09:14:29
我只看见MODEL.H5没看见STM32F767AI.H5,为什么
木木&点点 回答时间:2019-1-21 16:11:57
hu-jian-li 发表于 2019-1-21 09:14$ I( s/ i! u. E, f; P. ^$ H
我只看见MODEL.H5没看见STM32F767AI.H5,为什么
2 m' [  x& z# s" J3 w
model.h5就是我们需要导入到工程里的AI Keras的训练好的模型
杨满意 回答时间:2019-1-21 16:52:12
解释下输出结果的含义
木木&点点 回答时间:2019-1-23 15:23:29
杨满意 发表于 2019-1-21 16:52+ Q6 p$ G2 ]) o3 S. T
解释下输出结果的含义
; {+ _) ^3 I$ u1 z* q# B3 Y
输出吗   这是去使用库的AI神经算法
h55 回答时间:2019-1-28 11:02:50
点点&木木 发表于 2019-1-21 16:11! O$ Y4 W( w- o/ B- C. e0 o% [. G
model.h5就是我们需要导入到工程里的AI Keras的训练好的模型

$ D' U7 Y1 b* G我导入model.h5就没反应了,没有出现他教程中的STM32F767AI.H5,请问要怎么操作
木木&点点 回答时间:2019-1-31 19:42:28
hu-jian-li 发表于 2019-1-28 11:02
- e7 H5 E( L/ U' d+ N* D6 k$ B我导入model.h5就没反应了,没有出现他教程中的STM32F767AI.H5,请问要怎么操作 ...
* r) s- V4 G* A7 B8 D( M/ E
导入到工程的时候,没出现STM32F767AI.h5吗6 m; D" \/ w4 d
123下一页
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版