TensorFlow Lite for Microcontrollers的Micro speech example實作

接續前面文章與環境設定,進行TensorFlow Lite for Microcontrollers的Micro speech example實作。這個實作對應SparkFun Edge、STM32F7 discovery kit與Arduino Nano 33 BLE Sense三塊開發板,SparkFun Edge與STM32F7 discovery kit開發板的實作環境在Ubuntu 16.04 64bits Linux,Arduino Nano 33 BLE Sense開發板的實作環境在Windows 7 64bits上。另外,請參照閱讀TinyML: Machine Learning with TensorFlow Lite on Arduino and Ultra-Low-Power Microcontrollers一書的第7章與第8章,以瞭解程式碼的細節與範例運作方式。首先,進行SparkFun Edge開發板的實作;在tensorflow原始碼的目錄下,先進入SparkFun編譯的Python虛擬環境:

conda activate sparkfun-tensorflow

用以下命令進行編譯與執行檔簽署:

make -f tensorflow/lite/micro/tools/make/Makefile TARGET=sparkfun_edge TAGS="cmsis-nn" micro_speech_bin

cp tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/keys_info0.py \
tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/keys_info.py

python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/create_cust_image_blob.py \
--bin tensorflow/lite/micro/tools/make/gen/sparkfun_edge_cortex-m4/bin/micro_speech.bin \
--load-address 0xC000 \
--magic-num 0xCB \
-o main_nonsecure_ota \
--version 0x0

python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/create_cust_wireupdate_blob.py \
--load-address 0x20000 \
--bin main_nonsecure_ota.bin \
-i 6 \
-o main_nonsecure_wire \
--options 0x1

接上SparkFun Edge開發板到主機上,用以下程序燒錄執行檔到板子上:

export DEVICENAME=/dev/ttyUSB0

export BAUD_RATE=921600

# 確保您的SparkFun Edge已連接到SparkFun USB-C Serial Basic,並透過USB連接到您的電腦 
# 仍然按著標記為14按鈕,按一下標記RST按鈕以重置電路板 
# 持續按著標記為14按鈕,電腦執行以下命令

python3 tensorflow/lite/micro/tools/make/downloads/AmbiqSuite-Rel2.0.0/tools/apollo3_scripts/uart_wired_update.py \
-b ${BAUD_RATE} ${DEVICENAME} \
-r 1 \
-f main_nonsecure_wire.bin \
-i 6

執行結果如下所示:

接下來進行STM32F7 discovery kit開發板實作,在SparkFun編譯的Python虛擬環境中執行以下命令:

make -f tensorflow/lite/micro/tools/make/Makefile TARGET=mbed TAGS="CMSIS disco_f746ng" generate_micro_speech_mbed_project

完成後用以下命令切換到Mbed編譯的Python虛擬環境:

conda deactivate

conda activate mbed

切換目錄到剛剛產生的Mbed專案:

cd tensorflow/lite/micro/tools/make/gen/mbed_cortex-m4/prj/micro_speech/mbed

用以下命令進行專案設定與編譯:

mbed config root .

mbed deploy

python -c 'import fileinput, glob;
for filename in glob.glob("mbed-os/tools/profiles/*.json"):
  for line in fileinput.input(filename, inplace=True):
    print line.replace("\"-std=gnu++98\"","\"-std=c++11\", \"-fpermissive\"")'

cd -

cp tensorflow/lite/micro/tools/make/downloads/cmsis/CMSIS/DSP/Include/arm_math.h tensorflow/lite/micro/tools/make/gen/mbed_cortex-m4/prj/micro_speech/mbed/mbed-os/cmsis/TARGET_CORTEX_M/

cd -

mbed compile -m DISCO_F746NG -t GCC_ARM

接上STM32F7 discovery kit開發板到主機上,用以下命令將執行檔上傳到STM32F7 discovery kit開發板:

cp ./BUILD/DISCO_F746NG/GCC_ARM/mbed.bin /media/yilintung/DIS_F746NG

執行結果如下所示:

最後進行Arduino Nano 33 BLE Sense開發板實作,先設定開發板與連接埠:

接著開啟micro_speech範例,並進行上傳:

編譯與上傳成功後,使用”序列埠監控視窗” 觀察執行結果:

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *