・2018/08/18
Raspberry Piで Google謹製の Bazelビルドツールをビルドして TensorFlowを自己ビルドする方法
(ラズパイで Google謹製の Bazelビルドツールをビルドして TensorFlowを自己ビルドする方法)
Tags: [Raspberry Pi], [電子工作], [ディープラーニング]
● Raspberry Piで TensorFlowのビルドに挑戦
TensorFlowをビルドするには Bazelと言うビルドツールが必要です。
Bazelはもともと Google社内で使用していたビルドツールです。
Bazelをビルドするのに苦労したので、まずは Bazelのビルド方法をまとめます。
●今回動かした Raspberry Pi Raspbian OSのバージョン
RASPBIAN STRETCH WITH DESKTOP
Version:June 2018
Release date: 2018-06-27
Kernel version: 4.14
pi@raspberrypi:~/pytorch $ uname -a
Linux raspberrypi 4.14.50-v7+ #1122 SMP Tue Jun 19 12:26:26 BST 2018 armv7l GNU/Linux
● Raspberry Piで Bazelを Gitソースリストからビルドする。
Bazel
Build and test software of any size, quickly and reliably
bazelbuild/bazel
a fast, scalable, multi-language and extensible build system https://bazel.build
ビルド方法。
Compiling Bazel from Source
必要なもの
Bash
zip, unzip
C++ build toolchain
JDK 8. You must install version 8 of the JDK.
Python. Versions 2 and 3 are supported.
使用した GCCは gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1)
# お決まりの sudo apt-get updateで最新状態に更新する
sudo apt-get update
# Bazelのビルドに必要な パッケージ群をインストールする
sudo apt-get install build-essential python zip unzip
# openjdk-8-jdkのインストールに失敗するので下記の通りに行なう
sudo apt-get -y purge openjdk-8-jre-headless
sudo apt-get -y install openjdk-8-jre-headless
sudo apt-get -y install openjdk-8-jre
sudo apt-get -y install openjdk-8-jdk
# Bazelのソースリスト一式を Gitの Releasesから取得する
# -distの zipを取得する事。(最初は -dist無しの Source code zipをダウンロードしてビルドができなくて悩んだ)
# 0.16.1 @bazel-io bazel-io released this Aug 13, 2018
cd
wget https://github.com/bazelbuild/bazel/releases/download/0.16.1/bazel-0.16.1-dist.zip
mkdir bazel-0.16.1-dist
cd bazel-0.16.1-dist
# ZIPファイルを解凍する
unzip ../bazel-0.16.1-dist.zip
# Bazelをビルドする時の環境変数を設定します
export BAZEL_JAVAC_OPTS="-J-Xmx512M"
# EXTRA_BAZEL_ARGS='--jobs=2'で Bazelを 2コアでビルドする
# 無指定だと 4コアでビルドしてメモリがあっぷあっぷになる
export EXTRA_BAZEL_ARGS='--jobs=2'
# ビルドする(timeコマンドを付けて時間計測も行なう)
# 大体 100分くらいでビルドが完了する
time ./compile.sh
# [2,234 / 2,267] 2 actions, 1 running
# //src/main/java/com/google/devtools/build/lib/worker:worker; 0s worker
# [Sched] Extracting interface //.../build/buildjar/javac/plugins:errorprone
その後、sudo cpで bazelのバイナリを /usr/local/bin/にコピーして、再度 Bazelを実行するとインストールが完了します。
# bazelのバイナリをコピー
sudo cp output/bazel /usr/local/bin/bazel
# bazelを実行でインストール完了(裏で bazelのサービスが動く)
bazel
# Extracting Bazel installation...
# Starting local Bazel server and connecting to it...
# [bazel release 0.16.1- (@non-git)]
pi@raspberrypi:~/bazel-0.16.1-dist $ bazel
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
[bazel release 0.16.1- (@non-git)]
Usage: bazel <command> <options> ...
Available commands:
analyze-profile Analyzes build profile data.
build Builds the specified targets.
canonicalize-flags Canonicalizes a list of bazel options.
clean Removes output files and optionally stops the server.
coverage Generates code coverage report for specified test targets.
cquery Loads, analyzes, and queries the specified targets w/ configurations.
dump Dumps the internal state of the bazel server process.
fetch Fetches external repositories that are prerequisites to the targets.
help Prints help for commands, or the index.
info Displays runtime info about the bazel server.
license Prints the license of this software.
mobile-install Installs targets to mobile devices.
print_action Prints the command line args for compiling a file.
query Executes a dependency graph query.
run Runs the specified target.
shutdown Stops the bazel server.
sync Syncs all repositories specifed in the workspace file
test Builds and runs the specified test targets.
version Prints version information for bazel.
Getting more help:
bazel help <command>
Prints help and options for <command>.
bazel help startup_options
Options for the JVM hosting bazel.
bazel help target-syntax
Explains the syntax for specifying targets.
bazel help info-keys
Displays a list of keys used by the info command.
pi@raspberrypi:~/bazel-0.16.1-dist $ bazel version
Build label: 0.16.1- (@non-git)
Build target: bazel-out/arm-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Sun Aug 19 15:03:36 2018 (1534691016)
Build timestamp: 1534691016
Build timestamp as int: 1534691016
● Bazelのビルド時間
ビルド時間にばらつきが有るね。
export EXTRA_BAZEL_ARGS='--jobs=2'で 2コアでビルドした場合。101分
INFO: From Building Java resource jar:
OpenJDK Client VM warning: TieredCompilation is disabled in this release.
Slow read: a 115863110-byte read from /tmp/bazel_HhynPjtp/out/execroot/io_bazel/bazel-out/arm-opt/bin/src/bazel_nojdk took 11843ms.
Target //src:bazel_nojdk up-to-date:
bazel-bin/src/bazel_nojdk
INFO: Elapsed time: 5132.941s, Critical Path: 1376.33s
INFO: 1851 processes: 1549 local, 302 worker.
INFO: Build completed successfully, 2267 total actions
WARNING: --batch mode is deprecated. Please instead explicitly shut down your Bazel server using the command "bazel shutdown".
Build successful! Binary is here: /home/pi/bazel-0.16.1-dist/output/bazel
real 100m55.830s
user 143m35.938s
sys 4m19.971s
●ラズパイ3B、32GB microSD
export BAZEL_JAVAC_OPTS="-J-Xmx512M"
export EXTRA_BAZEL_ARGS='--jobs=2'
Build successful! Binary is here: /home/pi/bazel-0.16.1-dist/output/bazel
real 87m56.157s
user 138m38.259s
sys 3m49.817s
●ラズパイ3B+、32GB microSD
export BAZEL_JAVAC_OPTS="-J-Xmx512M"
export EXTRA_BAZEL_ARGS='--jobs=2'
Build successful! Binary is here: /home/pi/bazel-0.16.1-dist/output/bazel
real 103m25.409s
user 123m24.699s
sys 3m41.033s
● 2回目
Build successful! Binary is here: /home/pi/bazel-0.16.1-dist/output/bazel
real 107m38.713s
user 127m54.080s
sys 3m39.757s
●ラズパイ3B+、32GB microSD
export BAZEL_JAVAC_OPTS="-J-Xmx512M"
export EXTRA_BAZEL_ARGS='--jobs=3'
Build successful! Binary is here: /home/pi/bazel-0.16.1-dist/output/bazel
real 96m16.821s
user 154m42.488s
sys 4m22.852s
● Bazelのバイナリサイズ
バイナリサイズにもばらつきが有るね。
pi@raspberrypi:~/bazel-0.16.1-dist $ ls -l ./output/bazel
-rwxr-xr-x 1 pi pi 115780695 Aug 19 03:47 ./output/bazel
再度ビルドした時 ラズパイ3B(なぜサイズが前回と異なる?)
pi@raspberrypi:~/bazel-0.16.1-dist $ ls -l ./output/bazel
-rwxr-xr-x 1 pi pi 115780660 Aug 19 16:18 ./output/bazel
再度ビルドした時 ラズパイ3B+(なぜサイズが前回と異なる?)
pi@raspberrypi:~/bazel-0.16.1-dist $ ls -l ./output/bazel
-rwxr-xr-x 1 pi pi 115780642 Aug 19 16:33 ./output/bazel
再再度ビルドした時 ラズパイ3B+(なぜサイズが前回と異なる?)
pi@raspberrypi:~/bazel-0.16.1-dist $ ls -l ./output/bazel
-rwxr-xr-x 1 pi pi 115780608 Aug 20 06:38 ./output/bazel
pi@raspberrypi:~/bazel-0.16.1-dist $ ls -l ./output/bazel
-rwxr-xr-x 1 pi pi 115780680 Aug 30 21:17 ./output/bazel
GCCは 6.3.0を使用(ラズパイのデフォルト)
pi@raspberrypi:~ $ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/arm-linux-gnueabihf/6/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: ../src/configure -v --with-pkgversion='Raspbian 6.3.0-18+rpi1+deb9u1' --with-bugurl=file:///usr/share/doc/gcc-6/README.Bugs --enable-languages=c,ada,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-6 --program-prefix=arm-linux-gnueabihf- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libitm --disable-libquadmath --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-6-armhf/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-6-armhf --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-6-armhf --with-arch-directory=arm --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-sjlj-exceptions --with-arch=armv6 --with-fpu=vfp --with-float=hard --enable-checking=release --build=arm-linux-gnueabihf --host=arm-linux-gnueabihf --target=arm-linux-gnueabihf
Thread model: posix
gcc version 6.3.0 20170516 (Raspbian 6.3.0-18+rpi1+deb9u1)
● Raspberry Piで openjdk-8-jdkのインストールに失敗する場合の解決方法
openjdk-8-jdkのインストールで下記のエラーメッセージが出て失敗します。
Error: missing `server' JVM at `/usr/lib/jvm/java-8-openjdk-armhf/jre/lib/arm/server/libjvm.so'.
dpkg: error processing package openjdk-8-jre-headless:armhf (--configure):
Package openjdk-8-jre-headless:armhf is not configured yet.
● Raspbian OSを SDカードにインストールした直後の状態
# お決まりの sudo apt-get updateで最新状態に更新する
sudo apt-get update
# openjdk-8-jdkのインストール(下記のエラーで失敗する)
sudo apt-get -y install openjdk-8-jdk
# openjdk-8-jdkのインストールでエラーの内容
Running hooks in /etc/ca-certificates/update.d...
Error: missing `server' JVM at `/usr/lib/jvm/java-8-openjdk-armhf/jre/lib/arm/server/libjvm.so'.
Please install or use the JRE or JDK that contains these missing components.
E: /etc/ca-certificates/update.d/jks-keystore exited with code 1.
done.
Setting up libatk-wrapper-java (0.33.3-13+deb9u1) ...
Processing triggers for hicolor-icon-theme (0.15-1) ...
dpkg: dependency problems prevent configuration of openjdk-8-jre-headless:armhf:
openjdk-8-jre-headless:armhf depends on ca-certificates-java; however:
Package ca-certificates-java is not configured yet.
dpkg: error processing package openjdk-8-jre-headless:armhf (--configure):
dependency problems - leaving unconfigured
Setting up x11proto-core-dev (7.0.31-1) ...
dpkg: dependency problems prevent configuration of openjdk-8-jdk-headless:armhf:
openjdk-8-jdk-headless:armhf depends on openjdk-8-jre-headless (= 8u181-b13-1~deb9u1); however:
Package openjdk-8-jre-headless:armhf is not configured yet.
dpkg: error processing package openjdk-8-jdk-headless:armhf (--configure):
dependency problems - leaving unconfigured
dpkg: dependency problems prevent configuration of openjdk-8-jdk:armhf:
openjdk-8-jdk:armhf depends on openjdk-8-jdk-headless (= 8u181-b13-1~deb9u1); however:
Package openjdk-8-jdk-headless:armhf is not configured yet.
dpkg: error processing package openjdk-8-jdk:armhf (--configure):
dependency problems - leaving unconfigured
Setting up libxau-dev:armhf (1:1.0.8-1) ...
dpkg: dependency problems prevent configuration of openjdk-8-jre:armhf:
openjdk-8-jre:armhf depends on openjdk-8-jre-headless (= 8u181-b13-1~deb9u1); however:
Package openjdk-8-jre-headless:armhf is not configured yet.
dpkg: error processing package openjdk-8-jre:armhf (--configure):
dependency problems - leaving unconfigured
Setting up libatk-wrapper-java-jni:armhf (0.33.3-13+deb9u1) ...
Setting up libxdmcp-dev:armhf (1:1.1.2-3) ...
Setting up libice-dev:armhf (2:1.0.9-2) ...
Setting up libxcb1-dev:armhf (1.12-1) ...
Setting up x11proto-input-dev (2.3.2-1) ...
Setting up libsm-dev:armhf (2:1.2.2-1+b1) ...
Setting up libx11-dev:armhf (2:1.6.4-3) ...
Setting up libxt-dev:armhf (1:1.1.5-1) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
Errors were encountered while processing:
ca-certificates-java
openjdk-8-jre-headless:armhf
openjdk-8-jdk-headless:armhf
openjdk-8-jdk:armhf
openjdk-8-jre:armhf
E: Sub-process /usr/bin/dpkg returned an error code (1)
● Raspberry Piで openjdk-8-jdkのインストールに失敗する場合の解決方法
openjdk-8-jre-headlessを一旦アンインストールして、再度インストールして、その後に openjdk-8-jdkをインストールする。
# openjdk-8-jdkのインストールに失敗するので下記の通りに行なう
# openjdk-8-jre-headlessを一旦アンインストール
sudo apt-get -y purge openjdk-8-jre-headless
# openjdk-8-jre-headlessを再度インストール
sudo apt-get -y install openjdk-8-jre-headless
# openjdk-8-jreを再度インストール
sudo apt-get -y install openjdk-8-jre
# 本命の openjdk-8-jdkをインストール
sudo apt-get -y install openjdk-8-jdk
※ラズパイの機嫌が悪い時や apt-getのサーバ側が混雑している場合は不可解なエラーが出る事があります。その場合は openjdk-8-jre-headlessのアンインストールからやり直します。
Tags: [Raspberry Pi], [電子工作], [ディープラーニング]
●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)
NVIDIA Jetson Nano 開発者キットを買ってみた。メモリ容量 4GB LPDDR4 RAM
Jetson Nanoで TensorFlow PyTorch Caffe/Caffe2 Keras MXNet等を GPUパワーで超高速で動かす!
Raspberry Piでメモリを馬鹿食いするアプリ用に不要なサービスを停止してフリーメモリを増やす方法
ラズパイでメモリを沢山使用するビルドやアプリ用に不要なサービス等を停止して使えるメインメモリを増やす
【成功版】最新版の Darknetに digitalbrain79版の Darknet with NNPACKの NNPACK処理を適用する
ラズパイで NNPACK対応の最新版の Darknetを動かして超高速で物体検出や DeepDreamの悪夢を見る
【成功版】Raspberry Piで NNPACK対応版の Darknet Neural Network Frameworkをビルドする方法
ラズパイに Darknet NNPACK darknet-nnpackをソースからビルドして物体検出を行なう方法
【成功版】Raspberry Piで Darknet Neural Network Frameworkをビルドする方法
ラズパイに Darknet Neural Network Frameworkを入れて物体検出や悪夢のグロ画像を生成する
【成功版】Raspberry Piに TensorFlow Deep Learning Frameworkをインストールする方法
ラズパイに TensorFlow Deep Learning Frameworkを入れて Google DeepDreamで悪夢を見る方法
Raspberry Piで TensorFlow Deep Learning Frameworkを自己ビルドする方法
ラズパイで TensorFlow Deep Learning Frameworkを自己ビルドする方法
Raspberry Piで Caffe Deep Learning Frameworkで物体認識を行なってみるテスト
ラズパイで Caffe Deep Learning Frameworkを動かして物体認識を行なってみる
【ビルド版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning Framework
ラズパイで Caffe Deep Learning Frameworkをビルドして Deep Dreamを動かしてキモイ絵を生成する
【インストール版】Raspberry Piで DeepDreamを動かしてキモイ絵をモリモリ量産 Caffe Deep Learning
ラズパイで Caffe Deep Learning Frameworkをインストールして Deep Dreamを動かしてキモイ絵を生成する
Raspberry Piで Caffe2 Deep Learning Frameworkをソースコードからビルドする方法
ラズパイで Caffe 2 Deep Learning Frameworkをソースコードから自己ビルドする方法
Orange Pi PC 2の 64bitのチカラで DeepDreamしてキモイ絵を高速でモリモリ量産してみるテスト
OrangePi PC2に Caffe Deep Learning Frameworkをビルドして Deep Dreamを動かしてキモイ絵を生成する
Raspberry Piに Jupyter Notebookをインストールして拡張子 ipynb形式の IPythonを動かす
ラズパイに IPython Notebookをインストールして Google DeepDream dream.ipynbを動かす
Raspberry Piで Deep Learningフレームワーク Chainerをインストールしてみる
ラズパイに Deep Learningのフレームワーク Chainerを入れてみた
Raspberry Piで DeepBeliefSDKをビルドして画像認識フレームワークを動かす方法
ラズパイに DeepBeliefSDKを入れて画像の物体認識を行なう
Raspberry Piで Microsoftの ELLをビルドする方法
ラズパイで Microsoftの ELL Embedded Learning Libraryをビルドしてみるテスト、ビルドするだけ
Raspberry Piで MXNet port of SSD Single Shot MultiBoxを動かして画像の物体検出をする方法
ラズパイで MXNet port of SSD Single Shot MultiBox Object Detectorで物体検出を行なってみる
Raspberry Piで Apache MXNet Incubatingをビルドする方法
ラズパイで Apache MXNet Incubatingをビルドしてみるテスト、ビルドするだけ
Raspberry Piで OpenCVの Haar Cascade Object Detectionでリアルタイムにカメラ映像の顔検出を行なってみる
ラズパイで OpenCVの Haar Cascade Object Detection Face & Eyeでリアルタイムでカメラ映像の顔検出をする方法
Raspberry Piで NNPACKをビルドする方法
ラズパイで NNPACKをビルドしてみるテスト、ビルドするだけ
Raspberry Pi 3の Linuxコンソール上で使用する各種コマンドまとめ
ラズパイの Raspbian OSのコマンドラインで使用する便利コマンド、負荷試験や CPUシリアル番号の確認方法等も
[HOME]
|
[BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c)
2018 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator
http://www.neko.ne.jp/~freewing/raspberry_pi/raspberry_pi_build_bazel_development_tool/