This post is Private. Only a writer or those who know its URL can access this post.

Article information
Show article in Markdown
Report article
Help us understand the problem. What is going on with this article?

TensorFlow for Android 勉強会@浜松

More than 3 years have passed since last update.

一時的な資料なのでイベント終わったらこの記事は消します(すべて整理してまた投稿し直します)

UbuntuのDockerコンテナがおすすめ

docker pull ubuntu:latest
docker run -it --rm ubuntu

セットアップ

# バージョンは適当に変えてください
SDK_VERSION=25.2.3
NDK_VERSION=r13b
SDK_API_VERSION=25
BUILD_TOOLS_VERSION=25.0.2
TENSORFLOW_TAG=v0.12.0

# ディレクトリは適当に変えてください
WORK_DIR=/home
LIB_DIR=/usr/local/lib

SDK_URL=https://dl.google.com/android/repository/tools_r${SDK_VERSION}-linux.zip
NDK_URL=https://dl.google.com/android/repository/android-ndk-${NDK_VERSION}-linux-x86_64.zip

cat >> /etc/profile << EOS
export ANDROID_HOME=${LIB_DIR}/android-sdk
export ANDROID_NDK_HOME=${LIB_DIR}/android-ndk-${NDK_VERSION}
EOS
cat >> /etc/profile << 'EOS'
export PATH=${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools
export PATH=${PATH}:${ANDROID_NDK_HOME}
EOS
source /etc/profile

# 好きなリポジトリにしてください
sed -i.bak -e "s%http://archive.ubuntu.com/ubuntu/%http://ftp.jaist.ac.jp/pub/Linux/ubuntu/%g" /etc/apt/sources.list

apt-get update
apt-get upgrade -y
apt-get install -y git curl unzip

echo "deb [arch=amd64] http://storage.googleapis.com/bazel-apt stable jdk1.8" | tee /etc/apt/sources.list.d/bazel.list
curl https://bazel.build/bazel-release.pub.gpg | apt-key add -

apt-get update && apt-get install -y bazel &

# 適当にハッシュチェックとかしてください
curl ${SDK_URL} -sSL -o /tmp/sdk.zip && unzip -q /tmp/sdk.zip -d ${LIB_DIR}/android-sdk &
curl ${NDK_URL} -sSL -o /tmp/ndk.zip && unzip -q /tmp/ndk.zip -d ${LIB_DIR} &

wait

apt-get clean

cd $WORK_DIR
git clone https://github.com/ornew/MNIST-for-Android.git
pushd MNIST-for-Android
pushd lib
cat > WORKSPACE << EOS
workspace(name = "mnist_android")

android_sdk_repository(
    name = "androidsdk",
    api_level = ${SDK_VERSION},
    build_tools_version = "${BUILD_TOOLS_VERSION}",
    path = "${ANDROID_HOME}",
)

android_ndk_repository(
    name = "androidndk",
    path = "${ANDROID_NDK_HOME}",
    api_level = 21)

git_repository(
    name = "org_tensorflow",
    remote = "https://github.com/tensorflow/tensorflow.git",
    init_submodules = 1,
    tag = "${TENSORFLOW_TAG}"
)

load("@org_tensorflow//tensorflow:workspace.bzl", "tf_workspace")
tf_workspace()
EOS

soのビルド

cd $WORK_DIR/MNIST-for-Android/lib
bazel build libmnist_android.so --crosstool_top=//external:android/crosstool --cpu=armeabi-v7a --host_crosstool_top=@bazel_tools//tools/cpp:toolchain

gradlewでコンソールからビルドする場合

cd $WORK_DIR/MNIST-for-Android
cp lib/bazel-bin/libmnist_android.so android/app/src/main/jniLibs/armeabi-v7a/
android list sdk -a | grep -E "SDK Platform Android .* API ${SDK_VERSION}" | awk '{sub(/.$/,"",$1);print $1}' | xargs -I{} sh -c "echo y | android update sdk -a -u -t {}"
android list sdk -a | grep "Android SDK Build-tools, revision ${BUILD_TOOLS_VERSION}" | awk '{sub(/.$/,"",$1);print $1}' | xargs -I{} sh -c "echo y | android update sdk -a -u -t {}"
android list sdk -a | grep "Android Support Repository" | awk '{sub(/.$/,"",$1);print $1}' | xargs -I{} sh -c "echo y | android update sdk -a -u -t {}"
cd android
bash ./gradlew build
# build/outputs/apk/app-debug.apk
dmmcom
総合エンタテイメントサイト「DMM.com」を運営。会員数は2,900万人を突破。動画配信、FX、英会話、ゲーム、太陽光発電、3Dプリンタなど40以上のサービスを展開。沖縄での水族館事業参入、ベルギーでのサッカークラブ経営など、様々な事業を手掛ける。また2018年より若手起業家の支援を強化、「DMM VENTURES」による出資や、M&Aなどを積極的に展開している。
https://dmm-corp.com
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした