LoginSignup
4
5

More than 3 years have passed since last update.

TensorFlow Lite のiOS GPU対応チュートリアルやってみた

Posted at

画像分類デモの取得と実行

準備

  • 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 ConfigurationDebugからReleaseに変更。Debug executableのチェックを外す。
2, Optionsタブをクリックす、GPU Frame CaptureDisabledMetal API ValidationDisabledに変更。
3, Project navigator -> tflite_camera_example -> PROJECT -> tflite_camera_example -> Build SettingsBuild Active Architecture Only > ReleaseYesに設定

  • ビルドし実行

デバイスを接続しXcodeからビルド、実行

参照

TensorFlow Lite image classification iOS example application
Tensor Flow Lite iOS quickstart
TensorFlow Lite GPU delegate

4
5
0

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
4
5