'Computer Learning/ai옮길것'에 해당되는 글 11건

  1. 2020.10.02 Microcontroller에서 tensorflowlite 실행
반응형

[지원되는 Microcontroller]

Tensorflowlite는 Microcontroller에서 실행된다. Tensorflow Lite for Microcontrollers로 명칭되며 C++11로 작성되며 32비트 플랫폼을 지원한다. 다음은 Tensorflow Lite가 지원되는 Microcontroller이다.

- Arduino Nano 33 BLE Sense

- Sparkfun Edge

- STM32F746 Discovery Kit

- Adafruit EdgeBadge

- AdafruitAdafruit TensorFlow Lite for Microcontrollers 키트
- Adafruit Circuit Playground Bluefruit
- Espressif ESP32-DevKitC
- Espressif ESP-EYE

 

[tensorflow lite 빌드]

이 중 arduino nano 33 ble sense에서 tensorflow lite의 예제를 실행해 보도록 하겠다. 

이후 예제는 ubuntu 18.04에서 테스트 하였다. ubuntu 18.04에서 다음으로 필요한 S/W를 설치한다.

 

$sudo apt-get install build-essential cmake python3 python3-pip curl gnupg openjdk-8-jdk

 

tensorflow lite의 make file을 이용해 컴파일 하려면 bazel을 설치해야 한다. (https://bazel.build)

 

$curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg

$sudo mv bazel.gpg /etc/apt/trusted.gpg.d/

$echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list

$sudo apt update && sudo apt install bazel-3.1.0 (tensorflow 소스에 따라 요구하는 버전이 다름)

 

tensorflow lite는 tensorflow 의 소스에 같이 배포 된다. 다음과 같이 cloning 한다

 

$git clone github.com/tensorflow/tensorflow.git

 

hello test 프로그램을 다음과 같이 빌드해 본다.

 

$make -f tensorflow/lite/micro/tools/make/Makefile test_hello_world_test

 

"fixedpoint/fixedpoint.h: No such file or directory" 오류가 발생하면 다음과 같이 다운로드 파일을 clear 하고 다시 빌드한다.

 

$make -f tensorflow/lite/micro/tools/make/Makefile clean_downloads
$make -f tensorflow/lite/micro/tools/make/Makefile clean
$make -f tensorflow/lite/micro/tools/make/Makefile test_hello_world_test

 

~~~ALL TEST PASSED~~~ 이 보이면 성공이다.

 

arduino IDE에서 Import 가능한 tensorflowlite zip 파일을 만드려면 tensorflow 폴더에서 다음을 임력한다

 

$./tensorflow/lite/micro/tools/ci_build/test_arduino.sh

 

이때 오류가 발생하면 $pip install six 로 라이브러리를 설치해 준다. 빌드에 꽤 시간이 걸리며 완료 되면 tensorflow/lite/micro/tools/make/gen/arduino_x86_64/prj/tensorflow_lite.zip 이 생성된다.

 

[arduino에서 빌드하기]

arduino를 설치하고 [툴 > 보드 > 보드매니저] 로 들어가 nano ble를 검색하고 nRF528x boards 를 선택해 설치한다.

그리고 [스케치 > 라이브러리포함하기 > .ZIP 라이브러리 추가]로 들어가서 tensorflow_lite.zip 을 추가해준다.

tensorflow_lite.zip을 추가하면 [파일 > 예제 > Arduino_TensorFlowLite ] 에 예제가 포함되어 있는 것을 알 수 있다.

보드를 "Arduino Nano 33 BLE"로 변경하고 컴파일 해야 오류가 발생하지 않는다.

 

반응형
Posted by alias
,