LoginSignup
30
27

More than 3 years have passed since last update.

TensorFlowのiOSサンプルの実行手順(2017年7月現在)

Last updated at Posted at 2017-07-01

【注意】本記事のサンプルは公開終了になっていました。(TensorFlow Liteに移行したようです。)

TensorFlowのiOSサンプルの実行手順について、すでにいろいろ情報は出ていますが、最新版では少し異なる箇所があったので、覚書としてまとめておきました。

はじめに

以下の環境で作業を行いました。
macOS 10.12.5
Xcode 8.3.3
TensorFlow Release 1.2.1 (2017/7/1 現在)

実は、今回行う手順は、以下のREADME.mdにまとまっています。
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/makefile
ただし、古い記述もありました。
(「tensorflow/contrib/ios_examples」から「tensorflow/examples/ios」に移動になったようです)
https://github.com/tensorflow/tensorflow/tree/master/tensorflow/examples/ios

できるだけ要点だけをまとめたかったので、ディレクトリ移動「cd」の記述は含めませんでした。

準備

automake, libtoolが必要になりますので、インストールしておきます。

brew install automake
brew install libtool

ダウンロード

TensorFlowライブラリ(tensorflow-master.zip)をダウンロードします。
https://github.com/tensorflow/tensorflow

画像認識用の学習済みモデル(inception5h.zip)をダウンロードします。
https://storage.googleapis.com/download.tensorflow.org/models/inception5h.zip

ビルド

TensorFlowライブラリのビルド

tensorflow/contrib/makefile

に移動して、以下を実行します。

./build_all_ios.sh

README.mdに「This process will take around twenty minutes on a modern MacBook Pro.」とありますが、私の環境(Retina, 13-inch, Early 2015)では1時間以上かかったと思います。ご注意ください。

iOSのサンプルプロジェクトのビルド

学習済みモデルのコピー

iOSのサンプルプロジェクトですが、以下に移動しています。(README.mdでの説明とは異なります)

tensorflow/examples/ios

今回は「camera」のサンプルプロジェクトで説明します。

ダウンロードした画像認識用の学習済みモデル(inception5h.zip)を解凍して、

tensorflow/examples/ios/camera/data

に以下のファイルをコピーします。

imagenet_comp_graph_label_strings.txt
tensorflow_inception_graph.pb

CocoaPodsのインストール

サンプルプロジェクトはCocoaPodsをインストールする必要があります。

tensorflow/examples/ios/camera

に移動して、以下を実行します。

pod install

もし上記で「Unable to find a specification for `TensorFlow-experimental`」というエラーが出た場合、以下の手順を行ってください。

pod repo remove master
pod setup

pod install

以下のxcworkspaceが作成されていれば成功です。

tensorflow/examples/ios/camera/tf_camera_example.xcworkspace

このxcworkspaceからXcodeを起動してください。
問題なくビルド、実行できると思います。

実行結果

とりあえず、自宅にあったギターを試してみました。

アコースティックギター

IMG_0514.PNG

エレキギター

IMG_0515.PNG

バッチリですね!

30
27
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
30
27