画像分類デモの取得と実行
準備
- Device: iOS 12.0以上
- Xcode 10.0以上
- Apple Developer ID
- Xcode command line tools
xcode-select --install
- CocoaPods
sudo gem install cocoapods
Build and Run
- デモのclone
git clone https://github.com/tensorflow/examples.git
- ワークスペースファイルの生成
cd examples/lite/examples/image_classification/ios
pod update
pod install
これにより、ImageClassification.xcworkspaceが作成される
- ワークスペースを開く
open ImageClassification.xcworkspace
- ビルドと実行
1, Xcode 内で、ImageClassificationを選択し、プロジェクト構成を開、[genenral]タブの[Signing]で開発チームを選択
2, Identity section内、そしてすべてのXcodeプロジェクトで一意になるようにBundle Identifierを変更
3,iOSデバイスを接続し、ビルド、実行
TensorFLow Liteの導入
- Swiftに追加
Podfile内に以下を追加しpod installし直す。
use_frameworks!
pod 'TensorFlowLiteSwift'
- ライブラリのインポート
SwiftファイルにTensorFlow Liteモジュールをインポート
import TensorFlowLite
TensorFLow Lite GPUの導入
- Swiftに追加
Podfile内に以下を追加しpod installし直す。
# pod 'TensorFlowLite'
pod 'TensorFlowLiteGpuExperimental'
- GPU Delegateを有効にする
CameraExampleViewController.hにおいて、
# define TFLITE_USE_GPU_DELEGATE 1
- リリースモードに変更
1, Product > Scheme > Edit Scheme...に進み、Runを選択、InfoタブのBuild ConfigurationをDebugからReleaseに変更。Debug executableのチェックを外す。
2, Optionsタブをクリックす、GPU Frame CaptureをDisabledにMetal API ValidationをDisabledに変更。
3, Project navigator -> tflite_camera_example -> PROJECT -> tflite_camera_example -> Build SettingsのBuild Active Architecture Only > ReleaseをYesに設定
- ビルドし実行
デバイスを接続しXcodeからビルド、実行
参照
TensorFlow Lite image classification iOS example application
Tensor Flow Lite iOS quickstart
TensorFlow Lite GPU delegate