TensorFlow Lite for Microcontrollers的Person detection example實作

接續前面文章與環境設定,進行TensorFlow Lite for Microcontrollers的Person detection example實作。這個實作只對應SparkFun Edge與Arduino Nano 33 BLE Sense兩塊開發板,SparkFun Edge開發板的實作環境在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一書的第9章與第10章,以瞭解程式碼的細節與範例運作方式。首先,進行SparkFun Edge開發板的實作;在tensorflow原始碼的目錄下,先進入SparkFun編譯的Python虛擬環境:

conda activate sparkfun-tensorflow

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

make -f tensorflow/lite/micro/tools/make/Makefile TARGET=sparkfun_edge person_detection_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/person_detection.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開發板與配套的攝影機如下圖所示:

接上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

執行結果如下所示:

接下來進行Arduino Nano 33 BLE Sense開發板實作,首先進行硬體組裝如下圖所示:

從GitHub上下載ArduCAM程式庫,解壓縮放到Arduino程式庫的目錄:

用外部編輯器,確認Arduino/libraries/ArduCAM/memorysaver.h內容:

接著安裝JPEG解碼程式庫:

用外部編輯器,修改Arduino/libraries/JPEGDecoder/src/User_Config.h:

接下來,設定開發板與連接埠:

開啟person_detection範例程式碼,並進行上傳:

執行結果如下所示:

附帶一提,以下是 Person detection example實作在Arduino Project Hub上的展示影片:

發表迴響

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