Cannot import tensorflow in Swift playground
Answers to your queries:
- Swift Playgrounds are not yet supported (available in future) by S4TF toolchains.
- You can only build app for macOS right now but support for other OSs will be available in future.
- 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 runningswift 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
Swift for TensorFlow `error: Couldn't lookup symbols: type metadata accessor for TensorFlow.Tensor`
Ok, it seems to be a known issue -
https://github.com/tensorflow/swift/issues/173
I can't use Python module in Swift
A year later, I got a solution.
The name of module was wrong.
import PythonKit
let np = Python.import("numpy")
I should have installed on this way and implemented this way exactly.
Thanks regards!
Xcode: 11.3.1
Swift: 4.2
Toolchain: Swift for TensorFlow 0.8 Release
swift playground error: module 'Python' has no member named 'import'
A few things to check.
Presumably you're using the swift / tensorflow toolchain from latest download link here (and you've configured Xcode to use it.
View Xcode’s (Preferences, Components > Toolchains, and select the installed Swift for TensorFlow toolchain.)
https://github.com/tensorflow/swift/blob/master/Installation.mdMake sure you change the Xcode build system to legacy (File > Project Settings > Build System).
Check the runtime search path
/Library/Developer/Toolchains/swift-latest/usr/lib/swift/macosx
UPDATE:
Have a look at XcodeGen which can automagically create an xcode project with relevant settings for swift for tensorflow.
I crafted a project.yml file here
DO NOT include libppython2.7.tbd in the linked frameworks. tensorflow will automagically find relevant python version 3 or 2.
OSLog Logger doesn't work on XCode Playground: Couldn't lookup symbols: ___dso_handle
There is a workaround to work with Logger
on Playgrounds. You should make new file inside your playground (e.g. Sources/Log.swift) and implement code there:
// Log.swift
import os
let logger = Logger()
public func log(_ text: String) {
logger.log("\(text)")
}
// MyLog.playground
log("Hello OSLog")
Got a fatal error saying JVP does not exist. Differential-first differentiation APIs are experimental and should not be used.
You're seeing that error because you're attempting to take a forward-mode derivative, and support for that hasn't yet been implemented in the Swift automatic differentiation system. The current implementation supports reverse-mode differentiation, so you can use the gradient
operator instead to obtain the result you want:
@differentiable
func f(_ x: Float) -> Float {
x * x
}
let dfdx = gradient(of: f)
dfdx(3) // 6
Forward-mode differentiation support is in the works, but the focus is presently on upstreaming the reverse-mode implementation and refining that first. As a disclaimer, I work on the Swift for TensorFlow team.
Related Topics
Swift Running Code in Periodically Background
How to Use The Spritekit Method Body(At: Cgpoint)
Difference Between Timestamp Stored and Current Date
It Is Posible to Load Customise HTML View into Webview in Swift
Back to Table View from Detail Page Without Reload, Swift
Programmatically Setting Texture in Scene Generated by Reality Composer
External Library Usage in Xcode
Encode Struct and Convert to Dictionary [String: Any]
Swift Corebluetooth Reading a Float Array from Ble
Swift Protocol That Is Using an Enum with Generic Associated Type
How to Calculate a Distance Between Two Anchorentities
Adding Data to a Specific UId in Firebase
How to Set Window Level in Swift
Pfuser That Created Object Cannot Delete Object Despite Acl Writing Access
Why Run Loop Is Needed When Using Dispatchqueue.Main.Async in MAC Command Line Tool in Swift
Swift Coredata: Unable to Section Tableview Using Sectionnamekeypath with Custom Function