티스토리 뷰

OS/Banana Pi /BPI-Bit

BPI-M2 Berry : Tensorflow Lite - 빌드

파란크리스마스 2020. 4. 2. 01:15
728x90

출처

swap 사이즈 설정

현재 swap 사이즈 확인

$ free -h
              total        used        free      shared  buff/cache   available
Mem:           998M        125M        814M        544K         58M        849M
Swap:          499M        141M        357M
$ sudo swapon -s
Filename                                Type            Size    Used    Priority
/dev/zram1                              partition       511416  145384  5
$ sudo swapoff /dev/zram1
$ sudo zramctl --reset /dev/zram1
$ sudo zramctl --find --size 2048M
/dev/zram1
$ sudo mkswap /dev/zram1
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=2b7262ae-3011-45d4-b3b5-c1d4eec0d5b6
$ sudo swapon /dev/zram1
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           998M        217M        706M        4.7M         75M        754M
Swap:          2.0G          0B        2.0G

Bazel 설치

출처 : トマト農家のロボット創り Robot creation by tomato farmer: Build Bazel(0.29.0) on Raspberry Pi 4

Bazel 다운로드 및 설치

$ mkdir bazel
$ cd bazel
$ wget https://github.com/bazelbuild/bazel/releases/download/0.29.1/bazel-0.29.1-dist.zip
$ unzip bazel-0.29.1-dist.zip
$ sudo env EXTRA_BAZEL_ARGS="--host_javabase=@local_jdk//:jdk" VERBOSE=yes BAZEL_JAVAC_OPTS="-J-Xms384m -J-Xmx1024m" bash ./compile.sh
$ sudo cp output/bazel /usr/local/bin/bazel

Tensorflow Lite 빌드

Tensorflow 소스 다운로드

$ wget https://github.com/tensorflow/tensorflow/archive/v2.1.0.tar.gz
$ tar -zxvf v2.1.0.tar.gz 
$ cd tensorflow-2.1.0/

Tensorflow Lite 빌드

$ sudo tensorflow/lite/tools/make/download_dependencies.sh
tensorflow/lite/tools/make/download_dependencies.sh: line 59: 1: Usage: download_and_extract URL DIR
$ sed -i "/^EIGEN_URL=/c\EIGEN_URL=\"\$(grep -o 'https://storage.googleapis.com/mirror.tensorflow.org/gitlab.com/libeigen/eigen/.*tar.gz' \"\${BZL_FILE_PATH}\")\"" tensorflow/lite/tools/make/download_dependencies.sh
$ sudo tensorflow/lite/tools/make/download_dependencies.sh
$ sudo tensorflow/lite/tools/make/build_lib.sh 
+ set -e
+++ dirname tensorflow/lite/tools/make/build_lib.sh
++ cd tensorflow/lite/tools/make
++ pwd
+ SCRIPT_DIR=/home/pi/tensorflow-2.1.0/tensorflow/lite/tools/make
+ TENSORFLOW_DIR=/home/pi/tensorflow-2.1.0/tensorflow/lite/tools/make/../../../..
+ make -j 4 BUILD_WITH_NNAPI=false -C /home/pi/tensorflow-2.1.0/tensorflow/lite/tools/make/../../../.. -f tensorflow/lite/tools/make/Makefile
make: Entering directory '/home/pi/tensorflow-2.1.0'
make: Nothing to be done for 'all'.
make: Leaving directory '/home/pi/tensorflow-2.1.0'

Tensorflow Lite C, C++ 예제 컴파일, 실행

$ cd tensorflow/lite/examples/minimal
$ ls
BUILD  minimal.cc
$ bazel build
Starting local Bazel server and connecting to it...
INFO: Options provided by the client:
  Inherited 'common' options: --isatty=1 --terminal_columns=124
INFO: Reading rc options for 'build' from /home/pi/tensorflow-2.1.0/.bazelrc:
  'build' options: --apple_platform_type=macos --define framework_shared_object=true --define open_source_build=true --java_toolchain=//third_party/toolchains/java:tf_java_toolchain --host_java_toolchain=//third_party/toolchains/java:tf_java_toolchain --define=use_fast_cpp_protos=true --define=allow_oversize_protos=true --spawn_strategy=standalone --strategy=Genrule=standalone -c opt --cxxopt=-std=c++14 --host_cxxopt=-std=c++14 --announce_rc --define=grpc_no_ares=true --noincompatible_remove_legacy_whole_archive --define=PREFIX=/usr --define=LIBDIR=$(PREFIX)/lib --define=INCLUDEDIR=$(PREFIX)/include --config=v2
INFO: Found applicable config definition build:v2 in file /home/pi/tensorflow-2.1.0/.bazelrc: --define=tf_api_version=2 --action_env=TF2_BEHAVIOR=1
WARNING: Usage: bazel build  .
Invoke `bazel help build` for full description of usage and options.
Your request is correct, but requested an empty set of targets. Nothing will be built.
DEBUG: Rule 'io_bazel_rules_docker' indicated that a canonical reproducible form can be obtained by modifying arguments shallow_since = "1556410077 -0400"
DEBUG: Call stack for the definition of repository 'io_bazel_rules_docker' which is a git_repository (rule definition at /home/pi/.cache/bazel/_bazel_pi/1e5f7ce23473dd292c5d0e986c50b880/external/bazel_tools/tools/build_defs/repo/git.bzl:195:18):
 - /home/pi/.cache/bazel/_bazel_pi/1e5f7ce23473dd292c5d0e986c50b880/external/bazel_toolchains/repositories/repositories.bzl:37:9
 - /home/pi/tensorflow-2.1.0/WORKSPACE:37:1
INFO: Analyzed 0 targets (0 packages loaded, 0 targets configured).
INFO: Found 0 targets...
INFO: Elapsed time: 47.550s, Critical Path: 0.13s
INFO: 0 processes.
INFO: Build completed successfully, 1 total action
$ ls
BUILD  minimal.cc
$ cd ../../tools/make/gen/linux_armv7l/bin/
$ ./minimal 
minimal <tflite model>

Tensorflow Lite 패키지 빌드, 설치

$ pip3 install /tmp/tflite_pip/python3/dist/tflite_runtime-2.1.0-cp37-cp37m-linux_armv7l.whl
Defaulting to user installation because normal site-packages is not writeable
Processing /tmp/tflite_pip/python3/dist/tflite_runtime-2.1.0-cp37-cp37m-linux_armv7l.whl
Requirement already satisfied: numpy>=1.12.1 in /usr/local/lib/python3.7/site-packages (from tflite-runtime==2.1.0) (1.18.2)
Installing collected packages: tflite-runtime
Successfully installed tflite-runtime-2.1.0
댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함