tensorflow / swift

Swift for TensorFlow
https://tensorflow.org/swift
Apache License 2.0
6.13k stars 608 forks source link

Support for iOS devices ? #563

Closed rekhakm closed 4 years ago

rekhakm commented 4 years ago

Swift for TensorFlow lets you build, train, test, and deploy machine learning models across a variety of platforms (Linux, macOS, Android, Windows).

Is there any plan to support IOS? if Yes can u publish some road maps

When integrating tflite models ,we might need some python interoperability to encrypt some data [model output] in IOS. What is the best way to run python code/libraries for encryption in IOS swift?

BradLarson commented 4 years ago

With the platforms listed above (Linux, macOS, Android, Windows), we've been able to use our custom Swift toolchains when building models and applications. Unfortunately, custom toolchains can't easily be used to deploy to iOS, so we've been limited by what is available within Xcode. However, this situation is improving with the upstreaming of differentiable programming into the Swift compiler.

There are two core components to the Swift for TensorFlow project: Swift differentiable programming and our higher-level machine learning APIs. I'm pleased to say that as of at least Xcode 12.2, Swift differentiable programming can be used in an experimental capacity to deploy to iOS devices. That's a significant step toward being able to target iOS.

The current versions of our higher-level APIs are layered on top of core TensorFlow, which is not intended for deployment to mobile devices. TensorFlow Lite is a distinct project with a focus on high-performance mobile inference. It is possible (and community members have demonstrated this in our design meetings) to export a model trained by Swift for TensorFlow and convert it to the model format ingested by TensorFlow Lite. That's one possible deployment path at present, but we're exploring alternative backends for our high-level APIs that could run on iOS. I unfortunately can't provide a concrete roadmap for that.

When it comes to encrypting and decrypting model output or weights, there are existing solutions for native Swift encryption and decryption that might work better than attempting to use Python interoperability (which might be tricky to get working on iOS). Swift Crypto would be the first project I'd look into for this.

shabalind commented 4 years ago

Closing for now, feel free to reopen if you have further questions.

H-G-Hristov commented 3 years ago

@BradLarson I am asking without checking first. If Android is a target. Is Swift (and thus Swift4TF) supported by Android Studio?

BradLarson commented 3 years ago

@H-G-Hristov - Swift code can deploy to Android devices (including automatic differentiation) in a few different ways:

You can build a Swift library targeting ARM32 or ARM64 Android devices which appears like any other NDK library and is accessed via JNI, then include that in your application. There are prebuilt toolchains for Android cross-compilation out there, I just don't have a link to one handy.

The Readdle developers went so far as to create a Gradle plugin to make it a little easier to build Swift code for Android.

Finally, the Scade IDE provides a means of building an Android application entirely in Swift. I'm not sure if their implementation incorporates Swift differentiable programming yet, however.