Một lớp bao gồm hai hoặc nhiều lớp khác một cách tuần tự.
Ví dụ:
- Xây dựng mô hình perceptron 2 lớp đơn giản cho MNIST:
let inputSize = 28 * 28
let hiddenSize = 300
var classifier = Sequential {
Dense<Float>(inputSize: inputSize, outputSize: hiddenSize, activation: relu)
Dense<Float>(inputSize: hiddenSize, outputSize: 3, activation: identity)
}
- Xây dựng bộ mã hóa tự động cho MNIST:
var autoencoder = Sequential {
// The encoder.
Dense<Float>(inputSize: 28 * 28, outputSize: 128, activation: relu)
Dense<Float>(inputSize: 128, outputSize: 64, activation: relu)
Dense<Float>(inputSize: 64, outputSize: 12, activation: relu)
Dense<Float>(inputSize: 12, outputSize: 3, activation: relu)
// The decoder.
Dense<Float>(inputSize: 3, outputSize: 12, activation: relu)
Dense<Float>(inputSize: 12, outputSize: 64, activation: relu)
Dense<Float>(inputSize: 64, outputSize: 128, activation: relu)
Dense<Float>(inputSize: 128, outputSize: imageHeight * imageWidth, activation: tanh)
}
Tuyên ngôn
public var layer1: Layer1
Tuyên ngôn
public var layer2: Layer2
Tuyên ngôn
public init(_ layer1: Layer1, _ layer2: Layer2)
Tuyên ngôn
@differentiable(wrt: self) public func callAsFunction(_ input: Layer1.Input) -> Layer2.Output
Tuyên ngôn
public init(@LayerBuilder layers: () -> `Self`)
Tuyên ngôn
@differentiable public func callAsFunction(_ input: Layer1.Input) -> Layer2.Output