Sequenziale

Mantieni tutto organizzato con le raccolte Salva e classifica i contenuti in base alle tue preferenze.
public struct Sequential<Layer1: Module, Layer2: Layer>: Module
    where Layer1.Output == Layer2.Input,
          Layer1.TangentVector.VectorSpaceScalar == Layer2.TangentVector.VectorSpaceScalar
extension Sequential: Layer where Layer1: Layer

Un livello che compone in sequenza due o più altri livelli.

Esempi:

  • Costruisci un semplice modello di perceptron a 2 strati per 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)
 }
  • Costruisci un codificatore automatico per 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)
}
  • Dichiarazione

    public var layer1: Layer1
  • Dichiarazione

    public var layer2: Layer2
  • Dichiarazione

    public init(_ layer1: Layer1, _ layer2: Layer2)
  • Dichiarazione

    @differentiable(wrt: self)
    public func callAsFunction(_ input: Layer1.Input) -> Layer2.Output
  • Dichiarazione

    public init(@LayerBuilder layers: () -> `Self`)

Disponibile dove `Layer1`: `Layer`

  • Dichiarazione

    @differentiable
    public func callAsFunction(_ input: Layer1.Input) -> Layer2.Output