Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Fix ParameterlessLayer conformances. #1034

Merged
merged 1 commit into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Sources/TensorFlow/Layers/Convolutional.swift
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ extension DepthwiseConv2D {

/// A layer for adding zero-padding in the temporal dimension.
public struct ZeroPadding1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// The padding values along the temporal dimension.
@noDerivative public let padding: (Int, Int)

Expand Down Expand Up @@ -821,6 +823,8 @@ public struct ZeroPadding1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer

/// A layer for adding zero-padding in the spatial dimensions.
public struct ZeroPadding2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// The padding values along the spatial dimensions.
@noDerivative public let padding: ((Int, Int), (Int, Int))

Expand Down Expand Up @@ -853,6 +857,8 @@ public struct ZeroPadding2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer

/// A layer for adding zero-padding in the spatial/spatio-temporal dimensions.
public struct ZeroPadding3D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// The padding values along the spatial/spatio-temporal dimensions.
@noDerivative public let padding: ((Int, Int), (Int, Int), (Int, Int))

Expand Down
5 changes: 5 additions & 0 deletions Sources/TensorFlow/Layers/Core.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import _Differentiation
/// A flatten layer flattens the input when applied without affecting the batch size.
@frozen
public struct Flatten<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// Creates a flatten layer.
public init() {}

Expand All @@ -37,6 +39,8 @@ public struct Flatten<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
/// A reshape layer.
@frozen
public struct Reshape<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// The target shape.
@noDerivative public var shape: Tensor<Int32>

Expand Down Expand Up @@ -70,6 +74,7 @@ public struct Reshape<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {

/// A layer that encloses a custom differentiable function.
public struct Function<Input: Differentiable, Output: Differentiable>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector
public typealias Body = @differentiable (Input) -> Output

@noDerivative public let body: Body
Expand Down
8 changes: 8 additions & 0 deletions Sources/TensorFlow/Layers/Dropout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ extension Tensor where Scalar: TensorFlowFloatingPoint {
/// training time, which helps prevent overfitting.
@frozen
public struct Dropout<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

@noDerivative public let probability: Double

/// Creates a dropout layer.
Expand Down Expand Up @@ -66,6 +68,8 @@ public struct Dropout<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
///
/// The noise added always has mean zero, but has a configurable standard deviation.
public struct GaussianNoise<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

@noDerivative public let standardDeviation: Tensor<Scalar>

/// Creates a Gaussian noise layer
Expand Down Expand Up @@ -95,6 +99,8 @@ public struct GaussianNoise<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer
/// Because this is a regularization layer, it is only active during training time. During inference,
/// `GaussianDropout` passes through the input unmodified.
public struct GaussianDropout<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

@noDerivative public let probability: Scalar
@noDerivative public let standardDeviation: Scalar

Expand Down Expand Up @@ -135,6 +141,8 @@ public struct GaussianDropout<Scalar: TensorFlowFloatingPoint>: ParameterlessLay
/// Source : Self-Normalizing Neural Networks: https://arxiv.org/abs/1706.02515
@frozen
public struct AlphaDropout<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

@noDerivative public let probability: Double

/// Initializes an `AlphaDropout` layer with a configurable `probability`.
Expand Down
26 changes: 26 additions & 0 deletions Sources/TensorFlow/Layers/Pooling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import _Differentiation
/// A max pooling layer for temporal data.
@frozen
public struct MaxPool1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// The size of the sliding reduction window for pooling.
@noDerivative public let poolSize: Int
/// The stride of the sliding window for temporal dimension.
Expand Down Expand Up @@ -56,6 +58,8 @@ public struct MaxPool1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
/// A max pooling layer for spatial data.
@frozen
public struct MaxPool2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// The size of the sliding reduction window for pooling.
@noDerivative public let poolSize: (Int, Int, Int, Int)
/// The strides of the sliding window for each dimension of a 4-D input.
Expand Down Expand Up @@ -105,6 +109,8 @@ extension MaxPool2D {
/// A max pooling layer for spatial or spatio-temporal data.
@frozen
public struct MaxPool3D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// The size of the sliding reduction window for pooling.
@noDerivative public let poolSize: (Int, Int, Int, Int, Int)
/// The strides of the sliding window for each dimension of a 5-D input.
Expand Down Expand Up @@ -171,6 +177,8 @@ extension MaxPool3D {
/// An average pooling layer for temporal data.
@frozen
public struct AvgPool1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// The size of the sliding reduction window for pooling.
@noDerivative public let poolSize: Int
/// The stride of the sliding window for temporal dimension.
Expand Down Expand Up @@ -210,6 +218,8 @@ public struct AvgPool1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
/// An average pooling layer for spatial data.
@frozen
public struct AvgPool2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// The size of the sliding reduction window for pooling.
@noDerivative public let poolSize: (Int, Int, Int, Int)
/// The strides of the sliding window for each dimension of a 4-D input.
Expand Down Expand Up @@ -259,6 +269,8 @@ extension AvgPool2D {
/// An average pooling layer for spatial or spatio-temporal data.
@frozen
public struct AvgPool3D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// The size of the sliding reduction window for pooling.
@noDerivative public let poolSize: (Int, Int, Int, Int, Int)
/// The strides of the sliding window for each dimension of a 5-D input.
Expand Down Expand Up @@ -325,6 +337,8 @@ extension AvgPool3D {
/// A global average pooling layer for temporal data.
@frozen
public struct GlobalAvgPool1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// Creates a global average pooling layer.
public init() {}

Expand All @@ -342,6 +356,8 @@ public struct GlobalAvgPool1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLay
/// A global average pooling layer for spatial data.
@frozen
public struct GlobalAvgPool2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// Creates a global average pooling layer.
public init() {}

Expand All @@ -359,6 +375,8 @@ public struct GlobalAvgPool2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLay
/// A global average pooling layer for spatial and spatio-temporal data.
@frozen
public struct GlobalAvgPool3D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// Creates a global average pooling layer.
public init() {}

Expand All @@ -376,6 +394,8 @@ public struct GlobalAvgPool3D<Scalar: TensorFlowFloatingPoint>: ParameterlessLay
/// A global max pooling layer for temporal data.
@frozen
public struct GlobalMaxPool1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// Creates a global max pooling layer.
public init() {}

Expand All @@ -396,6 +416,8 @@ public struct GlobalMaxPool1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLay
/// A global max pooling layer for spatial data.
@frozen
public struct GlobalMaxPool2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// Creates a global max pooling layer.
public init() {}

Expand All @@ -413,6 +435,8 @@ public struct GlobalMaxPool2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLay
/// A global max pooling layer for spatial and spatio-temporal data.
@frozen
public struct GlobalMaxPool3D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// Creates a global max pooling layer.
public init() {}

Expand All @@ -431,6 +455,8 @@ public struct GlobalMaxPool3D<Scalar: TensorFlowFloatingPoint>: ParameterlessLay
/// Note: `FractionalMaxPool` does not have an XLA implementation, and thus may have performance implications.
@frozen
public struct FractionalMaxPool2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

/// Pooling ratios for each dimension of input of shape (batch, height, width, channels).
/// Currently pooling in only height and width is supported.
@noDerivative public let poolingRatio: (Double, Double, Double, Double)
Expand Down
6 changes: 6 additions & 0 deletions Sources/TensorFlow/Layers/Upsampling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import _Differentiation
/// An upsampling layer for 1-D inputs.
@frozen
public struct UpSampling1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

@noDerivative public let size: Int

/// Creates an upsampling layer.
Expand All @@ -43,6 +45,8 @@ public struct UpSampling1D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer
/// An upsampling layer for 2-D inputs.
@frozen
public struct UpSampling2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

@noDerivative public let size: Int

/// Creates an upsampling layer.
Expand Down Expand Up @@ -70,6 +74,8 @@ public struct UpSampling2D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer
/// An upsampling layer for 3-D inputs.
@frozen
public struct UpSampling3D<Scalar: TensorFlowFloatingPoint>: ParameterlessLayer {
public typealias TangentVector = EmptyTangentVector

@noDerivative public let size: Int

/// Creates an upsampling layer.
Expand Down