README.md
1# TensorFlow Lite for Objective-C
2
3[TensorFlow Lite](https://www.tensorflow.org/lite/) is TensorFlow's lightweight
4solution for Objective-C developers. It enables low-latency inference of
5on-device machine learning models with a small binary size and fast performance
6supporting hardware acceleration.
7
8## Build TensorFlow with iOS support
9
10To build the Objective-C TensorFlow Lite library on Apple platforms,
11[install from source](https://www.tensorflow.org/install/source#setup_for_linux_and_macos)
12or [clone the GitHub repo](https://github.com/tensorflow/tensorflow).
13Then, configure TensorFlow by navigating to the root directory and executing the
14`configure.py` script:
15
16```shell
17python configure.py
18```
19
20Follow the prompts and when asked to build TensorFlow with iOS support, enter `y`.
21
22### CocoaPods developers
23
24Add the TensorFlow Lite pod to your `Podfile`:
25
26```ruby
27pod 'TensorFlowLiteObjC'
28```
29
30Then, run `pod install`.
31
32In your Objective-C files, import the umbrella header:
33
34```objectivec
35#import "TFLTensorFlowLite.h"
36```
37
38Or, the module if you set `CLANG_ENABLE_MODULES = YES` in your Xcode project:
39
40```objectivec
41@import TFLTensorFlowLite;
42```
43
44Note: To import the TensorFlow Lite module in your Objective-C files, you must
45also include `use_frameworks!` in your `Podfile`.
46
47### Bazel developers
48
49In your `BUILD` file, add the `TensorFlowLite` dependency to your target:
50
51```python
52objc_library(
53 deps = [
54 "//tensorflow/lite/objc:TensorFlowLite",
55 ],
56)
57```
58
59In your Objective-C files, import the umbrella header:
60
61```objectivec
62#import "TFLTensorFlowLite.h"
63```
64
65Or, the module if you set `CLANG_ENABLE_MODULES = YES` in your Xcode project:
66
67```objectivec
68@import TFLTensorFlowLite;
69```
70
71Build the `TensorFlowLite` Objective-C library target:
72
73```shell
74bazel build tensorflow/lite/objc:TensorFlowLite
75```
76
77Build the `tests` target:
78
79```shell
80bazel test tensorflow/lite/objc:tests
81```
82
83#### Generate the Xcode project using Tulsi
84
85Open the `//tensorflow/lite/objc/TensorFlowLite.tulsiproj` using
86the [TulsiApp](https://github.com/bazelbuild/tulsi)
87or by running the
88[`generate_xcodeproj.sh`](https://github.com/bazelbuild/tulsi/blob/master/src/tools/generate_xcodeproj.sh)
89script from the root `tensorflow` directory:
90
91```shell
92generate_xcodeproj.sh --genconfig tensorflow/lite/objc/TensorFlowLite.tulsiproj:TensorFlowLite --outputfolder ~/path/to/generated/TensorFlowLite.xcodeproj
93```
94