From 12528f30114d9503d6223f5d392d90b6404cb178 Mon Sep 17 00:00:00 2001 From: PAWAN SASANKA AMMANAMANCHI Date: Tue, 2 Apr 2019 15:47:34 +0530 Subject: [PATCH 1/2] Adding GlobalAveragePooling 3D --- Sources/DeepLearning/Layer.swift | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Sources/DeepLearning/Layer.swift b/Sources/DeepLearning/Layer.swift index 73f1b263a..9b06ca996 100644 --- a/Sources/DeepLearning/Layer.swift +++ b/Sources/DeepLearning/Layer.swift @@ -1022,7 +1022,7 @@ public struct GlobalAveragePooling1D: Layer { /// - input: The input to the layer. /// - context: The contextual information for the layer application, e.g. the current learning /// phase. - /// - Returns: The output + /// - Returns: The output @differentiable public func applied(to input: Tensor, in _: Context) -> Tensor { return input.mean(alongAxes: 1).reshaped(to: [input.shape[0], input.shape[2]]) @@ -1048,6 +1048,25 @@ public struct GlobalAveragePooling2D: Layer { } } +/// A global average pooling layer for spatial and spatio-temporal data. +@_fixed_layout +public struct GlobalAveragePooling3D: Layer { + /// Creates a global average pooling layer. + 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: [1,2,3]).reshaped(to: [input.shape[0], input.shape[4]]) + } +} + /// A layer that applies layer normalization over a mini-batch of inputs. /// /// Reference: [Layer Normalization](https://arxiv.org/abs/1607.06450). From 2bec02a44118ea3984bf1901e633972dc8e3df47 Mon Sep 17 00:00:00 2001 From: PAWAN SASANKA AMMANAMANCHI Date: Tue, 2 Apr 2019 16:36:46 +0530 Subject: [PATCH 2/2] Review Changes --- Sources/DeepLearning/Layer.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/DeepLearning/Layer.swift b/Sources/DeepLearning/Layer.swift index 9b06ca996..7c4cf1d23 100644 --- a/Sources/DeepLearning/Layer.swift +++ b/Sources/DeepLearning/Layer.swift @@ -1022,7 +1022,7 @@ public struct GlobalAveragePooling1D: Layer { /// - input: The input to the layer. /// - context: The contextual information for the layer application, e.g. the current learning /// phase. - /// - Returns: The output + /// - Returns: The output. @differentiable public func applied(to input: Tensor, in _: Context) -> Tensor { return input.mean(alongAxes: 1).reshaped(to: [input.shape[0], input.shape[2]]) @@ -1060,10 +1060,10 @@ public struct GlobalAveragePooling3D: Layer { /// - input: The input to the layer. /// - context: The contextual information for the layer application, e.g. the current learning /// phase. - /// - Returns: The output + /// - Returns: The output. @differentiable public func applied(to input: Tensor, in _: Context) -> Tensor { - return input.mean(alongAxes: [1,2,3]).reshaped(to: [input.shape[0], input.shape[4]]) + return input.mean(alongAxes: [1, 2, 3]).reshaped(to: [input.shape[0], input.shape[4]]) } }