在SparkFun Edge開發板上執行TensorFlow Lite for Microcontrollers的Hello World example

GitHub上TensorFlow master分支上有TensorFlow Lite的“Hello World”範例,資訊來自TensorFlow推特轉貼訊息:

官方執行範例在SparkFun Edge開發板如下:

該模型是學習Sine函數,使用TensorFlow Keras的顺序(Sequential)模型建構之神經網路;其Python程式碼請參照該專案的Notebook。本文是說明如何在SparkFun Edge開發板上實作這個範例。本次實作開發環境為macOS Mojave 10.14.5(with Xcode 10.2.1),且已安裝Anaconda for macOS Python 3.7 version;並已建立好虛擬環境,相關資訊請參考這篇文章。首先,進入sparkfun-tensorflow虛擬環境:

conda activate sparkfun-tensorflow

接著從GitHub取得TensorFlow master分支:

cd ~

git clone https://github.com/tensorflow/tensorflow.git

cd tensorflow

使用以下命令進行編譯:

make -f tensorflow/lite/experimental/micro/tools/make/Makefile TARGET=sparkfun_edge hello_world_bin

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

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

python tensorflow/lite/experimental/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

完成後使用以下命令進行燒錄:

export DEVICENAME=/dev/cu.wchusbserial14220

export BAUD_RATE=921600

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

python tensorflow/lite/experimental/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

完成燒錄後,按板上RST按鈕以重置電路板,就可以看到範例程式運作;並可用以下命令確認除錯訊息:

screen ${DEVICENAME} 115200

若要結束確認,在終端機上以Ctrl+A按下K,然後按下Y。

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *