Amit Gupta
Amit Gupta

Reputation: 302

Cannot import tensorflow in Swift playground

I am an iOS developer and trying to learn tensorflow

for my Xcode 11.2.1. I tried installing tensorflow using this link

I got the package in Xcode toolchain.

enter image description here

But after installation when I verified installation, it failed. Swift playground is giving error

No such module 'TensorFlow'

I created a new SwiftPlayground for macOS, still, no avail.

Later I again installed tensorflow through command-line from here and it too was successful. enter image description here

This time I had created a normal swift file to verify installation, but this too failed.

There is an existing old question on same issue, but that has not been helpful to me. Can anyone help me knows solution to this?

Upvotes: 0

Views: 860

Answers (2)

user12657810
user12657810

Reputation:

Also, if you, as an iOS developer, want to deploy a model into an iOS app without "leaving Xcode (almost)", you may be able to replicate what this developer did here. The author of that PDF presented at a S4TF design meeting not long ago. You may have seen this in the Google Groups discussion.

A workaround for model saving for you could be: use Python interop > import Keras > ... > Save model as .h5. Then, perhaps, you could use Apple's Python-based coremltools for Keras to integrate the model—now in the .mlmodel format— into your iOS app. I haven't tested this yet.

Upvotes: 0

Rahul
Rahul

Reputation: 127

Answers to your queries:

  1. Swift Playgrounds are not yet supported (available in future) by S4TF toolchains.
  2. You can only build app for macOS right now but support for other OSs will be available in future.
  3. Before you run your Swift file via CMD you need to export PATH=/Library/Developer/Toolchains/{swift-toolchain}/usr/bin/"${PATH}" where you should replace {swift-toolchain} with your S4TF toolchain name (clicking tab will suggest you available toolchains on your system). Then running swift test.swift will be (hopefully) successful.

Note: S4TF is still in early stage of development & is ready for beginners and researchers to work with it. But I personally feel that if you're developing an app for iOS it's a little early. I hope Apple with announce this feature in WWDC either in 2020 or 2021.

I hope this was helpful!

-- Rahul Bhalley

Upvotes: 2

Related Questions