Skip to content

Files

Latest commit

8cf3f16 · Nov 4, 2024

History

History

swift

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Jul 13, 2024
Nov 24, 2020
Nov 24, 2020
Dec 21, 2022
Apr 20, 2021
Apr 24, 2024
Apr 18, 2024
Nov 24, 2020
Oct 3, 2023
Oct 31, 2024

TensorFlow Lite for Swift

TensorFlow Lite is TensorFlow's lightweight solution for Swift developers. It enables low-latency inference of on-device machine learning models with a small binary size and fast performance supporting hardware acceleration.

Build TensorFlow with iOS support

To build the Swift TensorFlow Lite library on Apple platforms, install from source or clone the GitHub repo. Then, configure TensorFlow by navigating to the root directory and executing the configure.py script:

python configure.py

Follow the prompts and when asked to build TensorFlow with iOS support, enter y.

CocoaPods developers

Add the TensorFlow Lite pod to your Podfile:

pod 'TensorFlowLiteSwift'

Then, run pod install.

In your Swift files, import the module:

import TensorFlowLite

Bazel developers

In your BUILD file, add the TensorFlowLite dependency to your target:

swift_library(
  deps = [
      "//tensorflow/lite/swift:TensorFlowLite",
  ],
)

In your Swift files, import the module:

import TensorFlowLite

Build the TensorFlowLite Swift library target:

bazel build tensorflow/lite/swift:TensorFlowLite

Build the Tests target:

bazel test tensorflow/lite/swift:Tests --swiftcopt=-enable-testing

Note: --swiftcopt=-enable-testing is required for optimized builds (-c opt).

Generate the Xcode project using Tulsi

Open the //tensorflow/lite/swift/TensorFlowLite.tulsiproj using the TulsiApp or by running the generate_xcodeproj.sh script from the root tensorflow directory:

generate_xcodeproj.sh --genconfig tensorflow/lite/swift/TensorFlowLite.tulsiproj:TensorFlowLite --outputfolder ~/path/to/generated/TensorFlowLite.xcodeproj