How to build and run the TensorFlow Lite iOS examples?

Viewed 1850
1 Answers

Here are instructions for building and running the following (22 Aug 2018) TensorFlow Lite iOS examples from both Source (Method 1) and Pod file (Method 2);

How to get the TensorFlow Lite iOS camera/sample example to run [tensorflow/contrib/lite/examples/ios/camera / simple]

(e.g. camera classification models; mobilenet_quant_v1_224.tflite/labels.txt, simple classification models; mobilenet_v1_1.0_224.tflite/labels.txt)

Method 1 (Source: integrate with existing project)

Instructions based on; https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/lite/g3doc/ios.md

  • git clone https://github.com/tensorflow/tensorflow
  • cd tensorflow
  • git checkout r1.10 (select a version of tensorflow that contains tensorflow/contrib/lite/download_dependencies.sh)
  • cd tensorflow/contrib/lite
  • ./download_dependencies.sh
  • ./build_ios_universal_lib.sh
  • cd examples/ios
  • ./download_models.sh (download tensorflow models to simple/data and camera/data)
  • Show the project navigator
  • Update various settings in your app to link against TensorFlow Lite (see tensorflow/contrib/lite/examples/ios/simple/simple.xcodeproj / camera/tflite_camera_example.xcworkspace for example):
    • select [APPLICATIONNAME] project (blue document icon) - [default target] - Build Phases
    • Link Binary With Libraries - add (+) library tensorflow/contrib/lite/gen/lib/libtensorflow-lite.a
    • select [APPLICATIONNAME] project (blue document icon) - [default target] - Build Settings
    • Library Search Paths - add [INSERTTENSORFLOWSOURCELOCATIONHERE]/tensorflow/contrib/lite/gen/lib
    • Header Search paths - add [INSERTTENSORFLOWSOURCELOCATIONHERE] (the root folder of the tensorflow git repository)
    • Header Search paths - add [INSERTTENSORFLOWSOURCELOCATIONHERE]/tensorflow/contrib/lite/downloads
    • Header Search paths - add [INSERTTENSORFLOWSOURCELOCATIONHERE]/tensorflow/contrib/lite/downloads/flatbuffers/include
    • C++11 support (or later) should be enabled by setting C++ Language Dialect to GNU++11 (or GNU++14), and C++ Standard Library to libc++.
  • project navigator - in [INSERTAPPLICATIONNAME] project (blue document icon) - create new group called data
  • drag and drop data folder items from tensorflow/contrib/lite/example/ios/simple/data (grace_hopper.jpg, labels.txt, mobilenet...) to the newly created data folder in xCode (when asked, select Destination: Copy items if needed)
  • modify the application's existing AppDelegate.m accordingly with tensorflow/contrib/lite/examples/ios/simple/AppDelegate.mm/.h contents
  • drag and drop source code items from tensorflow/contrib/lite/example/ios/simple (ios_image_load.h, ios_image_load.mm, RunModelViewController.h, RunModelViewController.mm, RunModelViewController.xib [NOT: AppDelegate.h, AppDelegate.mm, main.mm])

Method 2 (Pod file)

Instructions based on; https://www.tensorflow.org/mobile/tflite/demo_ios

  • git clone https://github.com/tensorflow/tensorflow
  • cd tensorflow
  • cd tensorflow/contrib/lite/examples/ios
  • ./download_models.sh (download tensorflow models to simple/data and camera/data)
  • cd camera/cd simple
  • pod repo update
  • pod install
  • open tflite_camera_example.xcworkspace / open simple.xcodeproj
  • select tflite_camera_example/simple project (blue document icon) - [default target] - General
  • select 'Automatically manage signing' (required for simple project)
  • Change project developer to [INSERTDEVELOPERNAMEHERE]
  • Build/run
Related