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

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

[复制链接]
木木&点点 发布时间:2019-1-6 17:29
偶然看到一篇好文章,分享给大家。
0 e% W4 }, f: g
+ m) a/ F9 f) k% E+ V% ]
1.jpg
3 g$ [( c6 Q) y; a' ?- h
今天介绍下ST官方刚刚推出的CubeMx 自带的X-CUBE-AI(Artificial intelligent)插件功能,可以给现有的STM32 M3-M7高性能的处理器添加基于训练好的ANN 的模型用于不同的数据分析处理。

9 W/ W0 K, I0 x6 j9 H- z8 {) T
使用STM32Cube.AI简化了人工神经网络映射

( C& ?0 u1 b. Z, }8 Z# M
1.可与流行的深度学习培训工具互操作
2.兼容许多IDE和编译器
3.传感器和RTOS无关
4.允许多个人工神经网络在单个STM32MCU上运行
5.完全支持超低功耗STM32MCU

( t! I+ e6 @) A# ?1 R. o; d' T
提高您的工作效率
# [6 h: N8 k7 ?
利用DeepLearning的强大功能提高信号处理性能并提高STM32应用程序的生产率。创建人工神经网络并将其映射到STM32(通过CubeMx自动生成优化的代码),而无需手动构建代码。
以上就做个简短的介绍,想了解更多有关STM32Cube.AI可以访问下面的链接:http://www.st.com/content/st_com ... 2_gl_social_dec2018
/ Q% C4 U) L( O2 ?7 w! N' E. A( n, G% X
那先前的准备工作就是需要安装最新版本的CubeMx 5.0.1
然后使用CubeMx 去安装X-CUBE-AI插件, 700多M的容量。。慢慢下载吧

: N9 e+ k3 f5 W3 m1 L
2.jpg

- s$ Z# Z9 O7 [5 c9 o
下载好后,CubeMx里的Artificial intelligent
激活Enable

- H  V  h7 @: L" Y2 n( \0 O1 W
3.jpg

' G$ d) z! ^& [' L
这里我们就可以看到里面的选项了
下载下来。。然后选择Keras 的AI API算法
: M/ X6 I$ D( K7 P4 _
4.jpg

. e$ s# w" i4 \8 w; {5 h
model.h5就是我们需要导入到工程里的AI Keras的训练好的模型
) u, P4 `+ J# U1 J9 x
5.jpg

1 l6 M% `1 I7 y8 F+ S1 ^
Human Activity Recognition Using Convolutional Neural Network in Keras
人类活动识别卷积神经网络算法模型
6.jpg

* u$ Z! m$ U" Q3 A" ]) a$ A+ p
然后我们导入到工程里
7.jpg

* J' S6 D( s6 `" I) z1 ~9 M
这里选择压缩参数,不同的压缩参数对MCU的flash容量
要求也不一样。。
8.jpg
2 @& d& O4 u3 p6 Q5 k3 ^
点击Analyze cube就好计算使用这个神经网络算法的ram和flash容量占用

# C# @0 I* u  @6 |
9.jpg
* K6 F0 n2 @1 N) `
好了结果出来了,

% K3 t- k) w$ P
10.jpg

: n# F+ N/ A( x* f1 V8 j
经过分析后Cube会自动列出可以使用的MCU
然后显示在列表里
11.jpg
' @3 E( S% ]7 V$ e7 S
这里举个例子,我们选择没有压缩优化
分析模型算法后的结果我没有匹配的MCU可以使用
8 V8 [& q0 o. \4 w' y
12.jpg
6 K5 e# a( [+ M- C5 Z& w
这是选择压缩比参数8的结果,可以支持很多的MCU使用这个神经网络算法。。

! {' k! @( J5 X/ k: U1 j
13.jpg
2 M( Q1 N9 A7 u
好了,这里我们就选择STM32F767ZI Nucleo 板卡作为 这次演示使用的板卡
; P7 l' p+ t# @$ G  F3 W
14.jpg
好了选择好了,板卡,我们还需要给它添加扩展库,也就是AI库
. V9 f  o( B. v& F" K, h% \" F; `% s% [* W# K: u
15.jpg
. B& ?; K" H1 r

) V' Z8 y- D# A4 G$ ]9 b
选择好Validation 和打勾 AI core
5 |) }0 T1 o0 M! g  v) @, k
16.jpg
( b# v* w& s9 P+ B% H4 U
然后在cube 左下方可以看到下图箭头 提示的插件功能

) ~& t$ V) `9 c2 w, C- a) E
17.jpg
1 W: e* T5 \5 q4 h; R6 `- L, b% c) M
我们需要打勾以下2个功能

+ C# Q. C2 t  M  x, i
18.jpg
6 y( n5 l: r2 N2 q$ f
然后创建我的AI算法名称,这个名称会在后续的里自动创建好。
/ L# @: ^0 o" \$ I' _
19.jpg
* Q% W4 m4 A/ j) `5 D, ~+ s
添加好,我们下载好的AI神经网络算法,然后再Analyze下就好。。打勾表示验证通过

5 M2 S$ s3 O7 G5 Q
20.jpg
1 `% q6 K: [1 N) a8 X
然后我们需要配置我们的mcu的 CPU ICache 和 CPU DCache

2 _. t& N6 i7 Z/ p1 |0 T3 q+ }
21.jpg
4 }, ^  k: F  I# b4 Z, i7 D% @2 a
然后配置MCU主频为216Mhz

# P6 E  ~: v$ B0 ^9 r
22.jpg
, b: m/ F1 _$ I
$ I  @/ Y0 E5 U- N! a
然后我们需要配置串口3和CubeMx进行通讯,验证我们工程。。。

2 `. w! [, H2 y& @
23.jpg

0 \& k! V: c+ G& P) |0 J
然后在 AI扩展功能里选择通讯端口为串口3

3 `: }# ^0 N- ]  c' R! l
24.jpg
好了,工程差不多创建好了。接下来就是 配置工程的路径好 我们配置使用IAR 编译环境。。 然后Heap 然后要配置到2000 这个很重要,要是设置少了 系统就会奔溃(切记)
  ?3 L6 j2 G' u9 A7 G- `4 k) n: h
  k! N! V. L1 ^+ a/ S
25.jpg

% j, \( ?3 x* |1 a, ]$ W/ w5 x
好了工程生成好了,我们就可以 使用IAR 打开工程了 工程如下,工程里自动生成了基于AI的算法的所以文件

* x9 M" q6 f3 r" d. u' r
26.jpg
/ R' k& g4 Q; w: m
这里可以看到,基于AI训练好的模型数据列表。。。
7 ~9 |& C& w0 T  b- s
27.jpg
( t, k. J5 X9 h1 l  P# J( e
好了,配置位STLINK,然后编译好就可以直接下载到板子上了
3 ]/ x+ W4 Y; f) [" w
28.jpg
% n) l" i, l+ U# k( N+ g  _
29.jpg
好了,现在我们需要回到CubeMx里,回到 AI扩展功能里。。 先重启下开发板,然后 点击Validation on target
- n5 c. @6 k* i" W
3 ?% }! t, H2 Q
30.jpg
" E4 g. e- z' P, R  z4 G% }
选择手动,然后选择对应的串口端口

, i( Q) a% Z1 j; A( h" g/ _- ?$ w8 `' D" i
31.jpg

6 v' |' }& [- n8 O0 a: m8 Q! ?
这里可以看到验证已经开始了‘

  z9 S! j1 e0 X, o$ g* i
32.jpg
好了,结果出来了。我们可以在串口输出的信息里看到有关的数据
: A; W! ~  x# v1 H
33.jpg

! y3 w% {- q8 o
34.jpg
35.jpg

+ `; k% B9 ~$ j
36.jpg

5 ]1 h' J8 _/ Y# R  i  J
4 r7 U# |# h& p6 g. u& D
好了,基于CubeMx+AI扩展库的使用就分享到这了,想了解更多关于 使用STM32 AI的朋友可以关注ST官网的教程。。。
收藏 3 评论33 发布时间:2019-1-6 17:29

举报

33个回答
单片机爱好者 回答时间:2019-5-25 21:12:11
Build target 'STM32F767_AI'3 _8 h5 m  E4 v7 j7 m9 S
assembling startup_stm32f767xx.s...7 c; T( r% w& }* F8 Q" Y- P4 S, Y
compiling main.c...
% m. B! s- B0 s3 A$ q../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
% h$ a( _" v+ ~1 g! A5 E* |  #include "network.h"
4 [8 c9 b$ z5 ]; k5 x' X, A../Src/main.c: 0 warnings, 1 error
& S$ H$ k3 ?2 \, o: `: b. }6 ~compiling app_x-cube-ai.c...; I; H) t0 t8 O7 K. E$ m: v' S
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
" u0 N8 o2 K) b; c) Y  #include "network.h"
0 m+ a" i# h4 p  j* B- K../Src/app_x-cube-ai.c: 0 warnings, 1 error7 |6 {7 `% j& o
compiling stm32f7xx_it.c...- [" O! ~: G* Z1 l) a6 w7 _
compiling stm32f7xx_hal_msp.c...
1 Y* j& k! m4 [1 b! u6 ^3 S0 ~compiling stm32f7xx_hal_cortex.c...
6 @# {6 Z# r" w! Acompiling stm32f7xx_hal_crc.c...% ^- I  W! O3 }2 u# p" \* Y6 C" A+ M
compiling stm32f7xx_hal_crc_ex.c...$ b( J7 z! N1 S& q8 R0 b) M6 O: i
compiling stm32f7xx_hal_tim.c...+ ?8 X6 r- @: n: R
compiling stm32f7xx_hal_tim_ex.c...5 D8 f- X/ X0 f. t: Q1 A3 M3 a
compiling stm32f7xx_hal_uart.c...
  E( B: w4 F$ H: c* v7 K) \" ]compiling stm32f7xx_hal_uart_ex.c...
2 m! m0 |+ P3 @6 H4 N/ ocompiling stm32f7xx_hal_rcc.c...; C1 Y7 r: g$ }% Y7 J
compiling stm32f7xx_hal_rcc_ex.c...
4 H- e/ T* c( U$ L3 G4 B$ S8 ]. {compiling stm32f7xx_hal_flash.c...8 _4 B7 h0 {0 d8 a6 q2 K- w- `
compiling stm32f7xx_hal_flash_ex.c...
* {5 L; H: ~1 w; V. j- ]( ^compiling stm32f7xx_hal_gpio.c...
  D/ G. w6 W. b( p; H* o! mcompiling stm32f7xx_hal_dma.c...
% G% `4 z$ ^+ f1 b; T# tcompiling stm32f7xx_hal_dma_ex.c...
' ?/ ]3 W2 J! \. Kcompiling stm32f7xx_hal_pwr.c..., I& h" H. _& f6 V3 g* H
compiling stm32f7xx_hal_pwr_ex.c...
- C% q3 A6 M- w* T" hcompiling stm32f7xx_hal.c...$ {. I! H: I" p/ f. m
compiling stm32f7xx_hal_i2c.c...
! R+ X% O7 u. C# r- \* l. b" T  Xcompiling stm32f7xx_hal_i2c_ex.c...# }7 i( G6 _* _
compiling stm32f7xx_hal_exti.c...6 D, d4 _9 O7 Y5 p$ s) {' V$ r" Q+ P
compiling system_stm32f7xx.c...
3 ^# K% k9 [5 {1 z1 Acompiling aiPbMgr.c...
. V( [% F- X* _! x. C6 s../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
$ }2 Z( }! e& X9 X0 R  #include "network.h"
8 \7 c% b* P- ^! a) T../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiPbMgr.c: 0 warnings, 1 error9 t/ `( C& O' P+ I
compiling aiTestUtility.c...
* |* j, n- ^  k8 a# O$ v6 v../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory2 Z$ `5 W5 f2 z2 C, J
  #include "network.h"5 p& O' C; A" |. l" o! Q0 U
../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiTestUtility.c: 0 warnings, 1 error$ ?8 P$ ]6 I2 t. ?/ k/ U
compiling aiValidation.c...
  t7 T; k: g! f4 H- c8 F5 F../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
& ?0 S( B; a2 |  T  #include "network.h"  c: Q4 o. C7 r2 z, o
../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiValidation.c: 0 warnings, 1 error
4 ?8 ?, ~3 w5 j# V, t# Y9 Q3 Mcompiling pb_common.c...
9 O" w6 s% k% ]compiling pb_decode.c...
; P- i; e, Z" ~6 |$ {) g# \2 ?compiling pb_encode.c...
, ?: H" v. x4 J$ R, a2 V, p: `compiling stm32msg.pb.c.../ Z: v* O' e0 _* A: j
"STM32F767_AI\STM32F767_AI.axf" - 5 Error(s), 0 Warning(s).
% Z! l1 F; r  Q  xTarget not created.
单片机爱好者 回答时间:2019-5-25 21:11:53
Build target 'STM32F767_AI'
; R" J- w, t3 T2 h3 gassembling startup_stm32f767xx.s...8 j3 ~: s  T. Z# F7 Q
compiling main.c...( `$ p6 d* F! u; f9 i( q& m& u
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory2 e1 ?) l, x( L. s7 W
  #include "network.h"
3 a6 x* z# y- Q1 ?../Src/main.c: 0 warnings, 1 error, c2 J+ `/ B  Z4 x5 I+ I2 E
compiling app_x-cube-ai.c.../ z( s# V  b4 z" ~/ D: u
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory8 a/ z! o! g$ C% ~$ z
  #include "network.h"
3 @. _, S" H% A" U$ W: W) b% a../Src/app_x-cube-ai.c: 0 warnings, 1 error; n$ {' Q) b  b! x# [
compiling stm32f7xx_it.c...: f- ?! O) x; g+ Q7 w
compiling stm32f7xx_hal_msp.c...
& E% B' Z+ y) c6 C7 u9 Ncompiling stm32f7xx_hal_cortex.c...
4 ~# Q4 r# @( D! @: F; q, x$ ]compiling stm32f7xx_hal_crc.c...# g, h8 e" ~/ u" X# T) }/ U  V
compiling stm32f7xx_hal_crc_ex.c...6 d1 ^- T" h( [1 Q! h0 s
compiling stm32f7xx_hal_tim.c...# {/ E' u* k4 E- m& M
compiling stm32f7xx_hal_tim_ex.c...
3 V, l/ z" e* g& U7 Scompiling stm32f7xx_hal_uart.c...
$ D, r1 h/ z  E8 B5 c: e- a7 Ecompiling stm32f7xx_hal_uart_ex.c..., [1 c3 K( C$ d* Q% A% I
compiling stm32f7xx_hal_rcc.c...
5 B; z* G& x9 pcompiling stm32f7xx_hal_rcc_ex.c...
9 n$ Y" o' v+ Hcompiling stm32f7xx_hal_flash.c.../ a  h# u2 O' C# ?: z
compiling stm32f7xx_hal_flash_ex.c...
6 g) `# }$ Z* ocompiling stm32f7xx_hal_gpio.c...
0 L/ r1 \3 P5 E. Ocompiling stm32f7xx_hal_dma.c...& t6 v: I& i1 f  Y
compiling stm32f7xx_hal_dma_ex.c...+ U8 @# m8 T% O& K( P
compiling stm32f7xx_hal_pwr.c...
7 c* Z( y5 m7 u: P3 hcompiling stm32f7xx_hal_pwr_ex.c...
5 \8 t. S. Z5 ~) N2 q+ Tcompiling stm32f7xx_hal.c...
+ d9 a7 |$ Y5 \8 b* Qcompiling stm32f7xx_hal_i2c.c...5 C: F+ l, L  F2 E) g7 G1 v
compiling stm32f7xx_hal_i2c_ex.c...
2 D. {! f7 Y+ V, B/ P2 Wcompiling stm32f7xx_hal_exti.c...9 i* f$ e- V2 z) Y; h
compiling system_stm32f7xx.c...0 e$ G: G0 o7 p- [) T& L2 Y
compiling aiPbMgr.c...- |* E6 k5 I* X: u
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory3 P# \4 ?; `: d' O
  #include "network.h"% O) A( q( f" |, G4 D" Y
../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiPbMgr.c: 0 warnings, 1 error
/ {5 b5 K; P& Qcompiling aiTestUtility.c...3 F6 s# a0 O$ X4 N6 J. w- _7 b
../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory
6 T! m8 X% L1 S" r% I8 M  #include "network.h"6 v8 N8 Z) [% P! x( G
../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiTestUtility.c: 0 warnings, 1 error* ~' Q' X! @3 D# n
compiling aiValidation.c...
9 T  d! A8 b. E) I9 Y../Inc/app_x-cube-ai.h(77): error:  #5: cannot open source input file "network.h": No such file or directory& m- D* o. V. ^! g# t" o0 [
  #include "network.h"
- e' y. W5 X& Q3 F$ E../Middlewares/ST/X-CUBE-AI_Application/Validation/Src/aiValidation.c: 0 warnings, 1 error. d) y8 B& s9 \/ Q6 D& Z) U  C2 R
compiling pb_common.c...
+ l$ \5 W& \3 T; F9 fcompiling pb_decode.c...: F1 x" ]2 S6 l$ ~9 @& a1 U
compiling pb_encode.c...
  j, \2 ]# z9 vcompiling stm32msg.pb.c...6 ]% f0 o1 q5 N4 Q3 a3 z, U
"STM32F767_AI\STM32F767_AI.axf" - 5 Error(s), 0 Warning(s)./ t6 D& u' e6 ]) q
Target not created.
Beatle 回答时间:2019-7-14 14:55:07
じ太阳当空照 发表于 2019-7-14 09:15
; Y' {3 y4 ^: o" @0 q我真的不知道是哪出了问题,求大神指导,我导入以后,选好芯片,然后点击Additional Software进去,里面 ...
# Y6 r9 X1 S) p( G$ V  _/ B
首先确保已经安装了AI库7 ^. h, U2 G# v0 a1 B

8 ?+ ?3 G' Z# v: f 1.png 1 f( H- l7 m- s$ L! d
使能Atificial intelligence后,配置好参数,确保自己使用的单片机是在列表中的。
$ e4 o+ p  L7 k' Y  E
: V! E# z, U- b" i/ I% c+ S- y# j6 H6 X2 I
2.png ; u3 i! }7 A7 ^" l, T+ c
3 T! @  ^$ U0 G# [; J; j

" ]: X7 q+ l' p: |
' A7 h$ ^+ h/ B如果确定上面操作无误,界面还是空的话那就看看这里的配置是否和你真实的路径是一致的。& B, S: D+ }% c; I6 k$ u& k

  {* M' G1 x2 e# {  P4 y 3.png
* ]# w& v6 O/ y) o8 u; g
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:464 \5 b9 V- i' P, Y% s
多谢分享。。

# Y5 q2 s! W- q厉害了大佬
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; S; t& ]" Q$ ^: z
我只看见MODEL.H5没看见STM32F767AI.H5,为什么
9 J6 T7 q5 V; x; @" J/ i
model.h5就是我们需要导入到工程里的AI Keras的训练好的模型
杨满意 回答时间:2019-1-21 16:52:12
解释下输出结果的含义
木木&点点 回答时间:2019-1-23 15:23:29
杨满意 发表于 2019-1-21 16:525 ?/ q. H" K2 Z/ y" C$ y
解释下输出结果的含义
2 [% m3 O) f6 c3 v" F+ y; g
输出吗   这是去使用库的AI神经算法
h55 回答时间:2019-1-28 11:02:50
点点&木木 发表于 2019-1-21 16:119 q$ `7 C* M$ T; i! ?) Y
model.h5就是我们需要导入到工程里的AI Keras的训练好的模型
% H6 H3 E: D) @% o; u3 Y' d
我导入model.h5就没反应了,没有出现他教程中的STM32F767AI.H5,请问要怎么操作
木木&点点 回答时间:2019-1-31 19:42:28
hu-jian-li 发表于 2019-1-28 11:029 _' {' ?. l' E5 R( r* w7 [
我导入model.h5就没反应了,没有出现他教程中的STM32F767AI.H5,请问要怎么操作 ...
: h, v/ n' b6 K3 Y; }
导入到工程的时候,没出现STM32F767AI.h5吗7 Y3 F0 Q* |/ x7 h  s4 a
123下一页
关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新和工艺
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版