qoncept/tensorswift
_TensorSwift_ is a lightweight library to calculate tensors, which has similar APIs to [_TensorFlow_](https://www.tensorflow.org/)'s. _TensorSwift_ is useful to simulate calculating tensors in Swift **using models trained by _TensorFlow_**.
Deep MNIST for Experts
[deep-mnist.gif]
The following code shows how to simulate Deep MNIST for Experts, a tutorial of TensorFlow, by TensorSwift.
public struct Classifier {
public let W_conv1: Tensor
public let b_conv1: Tensor
public let W_conv2: Tensor
public let b_conv2: Tensor
public let W_fc1: Tensor
public let b_fc1: Tensor
public let W_fc2: Tensor
public let b_fc2: Tensor
public func classify(_ x_image: Tensor) -> Int {
let h_conv1 = (x_image.conv2d(filter: W_conv1, strides: [1, 1, 1]) + b_conv1).relu()
let h_pool1 = h_conv1.maxPool(kernelSize: [2, 2, 1], strides: [2, 2, 1])
let h_conv2 = (h_pool1.conv2d(filter: W_conv2, strides: [1, 1, 1]) + b_conv2).relu()
let h_pool2 = h_conv2.maxPool(kernelSize: [2, 2, 1], strides: [2, 2, 1])
let h_pool2_flat = h_pool2.reshaped([1, Dimension(7 * 7 * 64)])
let h_fc1 = (h_pool2_flat.matmul(W_fc1) + b_fc1).relu()
let y_conv = (h_fc1.matmul(W_fc2) + b_fc2).softmax()
return y_conv.elements.enumerated().max { $0.1 < $1.1 }!.0
}
}Installation
Swift Package Manager
.Package(url: "git@github.com:qoncept/TensorSwift.git", from: "0.2.0"),CocoaPods
pod 'TensorSwift', '~> 0.2'Carthage
github "qoncept/TensorSwift" ~> 0.2License
Package Metadata
Repository: qoncept/tensorswift
Default branch: master
README: README.md