@@ -26,11 +26,11 @@ public struct Conv1D<Scalar: TensorFlowFloatingPoint>: Layer {
26
26
public typealias Activation = @differentiable ( Tensor < Scalar > ) -> Tensor < Scalar >
27
27
/// The element-wise activation function.
28
28
@noDerivative public let activation : Activation
29
- /// The stride of the sliding window for temporal dimension.
29
+ /// The stride of the sliding window for the temporal dimension.
30
30
@noDerivative public let stride : Int
31
31
/// The padding algorithm for convolution.
32
32
@noDerivative public let padding : Padding
33
- /// The dilation factor for temporal dimension.
33
+ /// The dilation factor for the temporal dimension.
34
34
@noDerivative public let dilation : Int
35
35
36
36
/// Creates a `Conv1D` layer with the specified filter, bias, activation function, stride, and
@@ -40,16 +40,16 @@ public struct Conv1D<Scalar: TensorFlowFloatingPoint>: Layer {
40
40
/// - filter: The 3-D convolution kernel `[width, inputChannels, outputChannels]`.
41
41
/// - bias: The bias vector `[outputChannels]`.
42
42
/// - activation: The element-wise activation function.
43
- /// - stride: The stride of the sliding window for temporal dimension.
43
+ /// - stride: The stride of the sliding window for the temporal dimension.
44
44
/// - padding: The padding algorithm for convolution.
45
- /// - dilation: The dilation factor for temporal dimension.
45
+ /// - dilation: The dilation factor for the temporal dimension.
46
46
public init (
47
47
filter: Tensor < Scalar > ,
48
48
bias: Tensor < Scalar > ,
49
- activation: @escaping Activation ,
50
- stride: Int ,
51
- padding: Padding ,
52
- dilation: Int
49
+ activation: @escaping Activation = identity ,
50
+ stride: Int = 1 ,
51
+ padding: Padding = . valid ,
52
+ dilation: Int = 1
53
53
) {
54
54
self . filter = filter
55
55
self . bias = bias
@@ -83,9 +83,9 @@ public extension Conv1D where Scalar.RawSignificand: FixedWidthInteger {
83
83
/// - Parameters:
84
84
/// - filterShape: The 3-D shape of the filter, representing
85
85
/// `[width, inputChannels, outputChannels]`.
86
- /// - stride: The stride of the sliding window for temporal dimension.
86
+ /// - stride: The stride of the sliding window for the temporal dimension.
87
87
/// - padding: The padding algorithm for convolution.
88
- /// - dilation: The dilation factor for temporal dimension.
88
+ /// - dilation: The dilation factor for the temporal dimension.
89
89
/// - activation: The element-wise activation function.
90
90
/// - generator: The random number generator for initialization.
91
91
///
@@ -119,7 +119,7 @@ public extension Conv1D {
119
119
/// - Parameters:
120
120
/// - filterShape: The 3-D shape of the filter, representing
121
121
/// `[width, inputChannels, outputChannels]`.
122
- /// - stride: The stride of the sliding window for temporal dimension.
122
+ /// - stride: The stride of the sliding window for the temporal dimension.
123
123
/// - padding: The padding algorithm for convolution.
124
124
/// - dilation: The dilation factor for the temporal dimension.
125
125
/// - activation: The element-wise activation function.
@@ -179,10 +179,10 @@ public struct Conv2D<Scalar: TensorFlowFloatingPoint>: Layer {
179
179
public init (
180
180
filter: Tensor < Scalar > ,
181
181
bias: Tensor < Scalar > ,
182
- activation: @escaping Activation ,
183
- strides: ( Int , Int ) ,
184
- padding: Padding ,
185
- dilations: ( Int , Int )
182
+ activation: @escaping Activation = identity ,
183
+ strides: ( Int , Int ) = ( 1 , 1 ) ,
184
+ padding: Padding = . valid ,
185
+ dilations: ( Int , Int ) = ( 1 , 1 )
186
186
) {
187
187
self . filter = filter
188
188
self . bias = bias
@@ -306,9 +306,9 @@ public struct Conv3D<Scalar: TensorFlowFloatingPoint>: Layer {
306
306
public init (
307
307
filter: Tensor < Scalar > ,
308
308
bias: Tensor < Scalar > ,
309
- activation: @escaping Activation ,
310
- strides: ( Int , Int , Int ) ,
311
- padding: Padding
309
+ activation: @escaping Activation = identity ,
310
+ strides: ( Int , Int , Int ) = ( 1 , 1 , 1 ) ,
311
+ padding: Padding = . valid
312
312
) {
313
313
self . filter = filter
314
314
self . bias = bias
@@ -323,9 +323,11 @@ public struct Conv3D<Scalar: TensorFlowFloatingPoint>: Layer {
323
323
/// - Returns: The output.
324
324
@differentiable
325
325
public func callAsFunction( _ input: Tensor < Scalar > ) -> Tensor < Scalar > {
326
- return activation ( conv3D ( input, filter: filter,
327
- strides: ( 1 , strides. 0 , strides. 1 , strides. 2 , 1 ) ,
328
- padding: padding) + bias)
326
+ return activation ( conv3D (
327
+ input,
328
+ filter: filter,
329
+ strides: ( 1 , strides. 0 , strides. 1 , strides. 2 , 1 ) ,
330
+ padding: padding) + bias)
329
331
}
330
332
}
331
333
@@ -423,9 +425,9 @@ public struct TransposedConv2D: Layer {
423
425
public init (
424
426
filter: Tensor < Float > ,
425
427
bias: Tensor < Float > ,
426
- activation: @escaping Activation ,
427
- strides: ( Int , Int ) ,
428
- padding: Padding
428
+ activation: @escaping Activation = identity ,
429
+ strides: ( Int , Int ) = ( 1 , 1 ) ,
430
+ padding: Padding = . valid
429
431
) {
430
432
self . filter = filter
431
433
self . bias = bias
@@ -448,9 +450,12 @@ public struct TransposedConv2D: Layer {
448
450
strides. 1 + ( filter. shape [ 1 ] * paddingIndex)
449
451
let c = filter. shape [ 2 ]
450
452
let newShape = Tensor < Int32 > ( [ Int32 ( batchSize) , Int32 ( w) , Int32 ( h) , Int32 ( c) ] )
451
- return activation ( conv2DBackpropInput ( input, shape: newShape, filter: filter,
452
- strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
453
- padding: padding) + bias)
453
+ return activation ( conv2DBackpropInput (
454
+ input,
455
+ shape: newShape,
456
+ filter: filter,
457
+ strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
458
+ padding: padding) + bias)
454
459
}
455
460
}
456
461
@@ -547,9 +552,9 @@ public struct DepthwiseConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
547
552
public init (
548
553
filter: Tensor < Scalar > ,
549
554
bias: Tensor < Scalar > ,
550
- activation: @escaping Activation ,
551
- strides: ( Int , Int ) ,
552
- padding: Padding
555
+ activation: @escaping Activation = identity ,
556
+ strides: ( Int , Int ) = ( 1 , 1 ) ,
557
+ padding: Padding = . valid
553
558
) {
554
559
self . filter = filter
555
560
self . bias = bias
@@ -564,9 +569,11 @@ public struct DepthwiseConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
564
569
/// - Returns: The output.
565
570
@differentiable
566
571
public func callAsFunction( _ input: Tensor < Scalar > ) -> Tensor < Scalar > {
567
- return activation ( depthwiseConv2D ( input, filter: filter,
568
- strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
569
- padding: padding) + bias)
572
+ return activation ( depthwiseConv2D (
573
+ input,
574
+ filter: filter,
575
+ strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
576
+ padding: padding) + bias)
570
577
}
571
578
}
572
579
0 commit comments