From 6d748f5cad96bcb51781c8a4657f76660ed14731 Mon Sep 17 00:00:00 2001 From: Brennan Saeta Date: Fri, 22 Feb 2019 07:31:45 +0000 Subject: [PATCH 1/2] Add default padding values. In the interest of progressive disclosure of complexity, and good default values, set the padding on the layer types to be `.valid`. This follows the Keras convention as well (https://keras.io/layers/convolutional/). --- 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 240202fa7..e48730e9d 100644 --- a/Sources/DeepLearning/Layer.swift +++ b/Sources/DeepLearning/Layer.swift @@ -172,7 +172,7 @@ public extension Conv2D where Scalar.RawSignificand: FixedWidthInteger { init( filterShape: (Int, Int, Int, Int), strides: (Int, Int) = (1, 1), - padding: Padding, + padding: Padding = .valid, activation: @escaping Activation = identity, generator: inout G ) { @@ -190,7 +190,7 @@ public extension Conv2D where Scalar.RawSignificand: FixedWidthInteger { init( filterShape: (Int, Int, Int, Int), strides: (Int, Int) = (1, 1), - padding: Padding, + padding: Padding = .valid, activation: @escaping Activation = identity ) { self.init(filterShape: filterShape, strides: strides, padding: padding, @@ -284,7 +284,7 @@ public struct MaxPool2D: Layer { /// The padding algorithm for pooling. @noDerivative let padding: Padding - public init(poolSize: (Int, Int), strides: (Int, Int), padding: Padding) { + public init(poolSize: (Int, Int), strides: (Int, Int), padding: Padding = .valid) { self.poolSize = (1, Int32(poolSize.0), Int32(poolSize.1), 1) self.strides = (1, Int32(strides.0), Int32(strides.1), 1) self.padding = padding From cf6d8a64bf13770d4b38fea9a2158ed4367107f2 Mon Sep 17 00:00:00 2001 From: Brennan Saeta Date: Fri, 22 Feb 2019 07:54:39 +0000 Subject: [PATCH 2/2] Add padding for `AvgPool` which I forgot the first time. --- 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 e48730e9d..c88302a2c 100644 --- a/Sources/DeepLearning/Layer.swift +++ b/Sources/DeepLearning/Layer.swift @@ -307,7 +307,7 @@ public struct AvgPool2D: Layer { /// The padding algorithm for pooling. @noDerivative let padding: Padding - public init(poolSize: (Int, Int), strides: (Int, Int), padding: Padding) { + public init(poolSize: (Int, Int), strides: (Int, Int), padding: Padding = .valid) { self.poolSize = (1, Int32(poolSize.0), Int32(poolSize.1), 1) self.strides = (1, Int32(strides.0), Int32(strides.1), 1) self.padding = padding