From 494399a2ee4ef3dcea6616561f6817e4467794f2 Mon Sep 17 00:00:00 2001 From: PAWAN SASANKA AMMANAMANCHI Date: Sat, 30 Mar 2019 05:42:29 +0530 Subject: [PATCH 1/3] Adding GlobalAveragePooling1D --- Sources/DeepLearning/Layer.swift | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Sources/DeepLearning/Layer.swift b/Sources/DeepLearning/Layer.swift index 4233e8121..d5e04a079 100644 --- a/Sources/DeepLearning/Layer.swift +++ b/Sources/DeepLearning/Layer.swift @@ -1009,12 +1009,32 @@ public struct AvgPool2D: Layer { } } + +/// A global average pooling layer for temporal data. +@_fixed_layout +public struct GlobalAveragePooling1D: Layer { + /// Creates a global average pooling layer in 1 dimension + public init() {} + + /// Returns the output obtained from applying the layer to the given input. + /// + /// - Parameters: + /// - input: The input to the layer. + /// - context: The contextual information for the layer application, e.g. the current learning + /// phase. + /// - Returns: The output + @differentiable + public func applied(to input: Tensor, in _: Context) -> Tensor { + return input.mean(alongAxes: axis) + } +} + /// A global average pooling layer for spatial data. @_fixed_layout public struct GlobalAveragePooling2D: Layer { /// Creates a global average pooling layer. public init() {} - + /// Returns the output obtained from applying the layer to the given input. /// /// - Parameters: From d4e218eeaca6bbe2301a906c9d8b7128f97ce98f Mon Sep 17 00:00:00 2001 From: Tanmay Bakshi Date: Mon, 1 Apr 2019 11:48:00 +0530 Subject: [PATCH 2/3] Review Changes Co-Authored-By: Shashi456 --- Sources/DeepLearning/Layer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/DeepLearning/Layer.swift b/Sources/DeepLearning/Layer.swift index d5e04a079..3ad878d29 100644 --- a/Sources/DeepLearning/Layer.swift +++ b/Sources/DeepLearning/Layer.swift @@ -1025,7 +1025,7 @@ public struct GlobalAveragePooling1D: Layer { /// - Returns: The output @differentiable public func applied(to input: Tensor, in _: Context) -> Tensor { - return input.mean(alongAxes: axis) + return input.mean(alongAxes: 1).reshaped(to: [input.shape[0], input.shape[2]]) } } From 97d773bda9d3d2f4c3db5af5afc90631390b531b Mon Sep 17 00:00:00 2001 From: Pawan Sasanka Ammanamanchi Date: Mon, 1 Apr 2019 15:30:19 +0530 Subject: [PATCH 3/3] Review Changes --- Sources/DeepLearning/Layer.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/DeepLearning/Layer.swift b/Sources/DeepLearning/Layer.swift index 3ad878d29..73f1b263a 100644 --- a/Sources/DeepLearning/Layer.swift +++ b/Sources/DeepLearning/Layer.swift @@ -1013,7 +1013,7 @@ public struct AvgPool2D: Layer { /// A global average pooling layer for temporal data. @_fixed_layout public struct GlobalAveragePooling1D: Layer { - /// Creates a global average pooling layer in 1 dimension + /// Creates a global average pooling layer. public init() {} /// Returns the output obtained from applying the layer to the given input.