GitHub - tensorflow/swift-apis: Deep learning library for Swift for TensorFlow
source link: https://github.com/tensorflow/swift-apis
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
Swift for TensorFlow APIs
This repository hosts Swift for TensorFlow's deep learning library, available both as a part of the Swift for TensorFlow toolchain and as a Swift package.
Requirements
- A latest Swift for TensorFlow toolchain.
Usage
A Swift for TensorFlow toolchain is required to use this package. Add the following to your Swift package manifest.
packages: [ .package(url: "https://github.com/tensorflow/swift-apis.git") ]
To get started, simply import TensorFlow
in your Swift code.
import TensorFlow struct Model: Layer { var l1, l2: Dense<Float> init(hiddenSize: Int) { l1 = Dense(inputSize: 2, outputSize: hiddenSize, activation: relu) l2 = Dense(inputSize: hiddenSize, outputSize: 1, activation: relu) } @differentiable(wrt: (self, input)) func applied(to input: Tensor<Float>) -> Tensor<Float> { let h1 = l1.applied(to: input) return l2.applied(to: h1) } } let optimizer = SGD<Model, Float>(learningRate: 0.02) var classifier = Model(hiddenSize: 4) let x: Tensor<Float> = ... let y: Tensor<Float> = ... for _ in 0..<1000 { let ?model = classifier.gradient { classifier -> Tensor<Float> in let ŷ = classifier.applied(to: x) let loss = meanSquaredError(predicted: ŷ, expected: y) print("Loss: \(loss)") return loss } optimizer.update(&classifier.allDifferentiableVariables, along: ?model) }
Building
swift build
Bugs
Please report bugs and feature requests using GitHub issues in this repository.
Community
Discussion about Swift for TensorFlow happens on the [email protected] mailing list.
Contributing
We welcome contributions: please read the Contributor Guide to get started. It's always a good idea to discuss your plans on the mailing list before making any major submissions.
Code of Conduct
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
The Swift for TensorFlow community is guided by our Code of Conduct, which we encourage everybody to read before participating.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK