@@ -794,7 +794,7 @@ public struct MaxPool1D<Scalar: TensorFlowFloatingPoint>: Layer {
794
794
/// - Returns: The output.
795
795
@differentiable
796
796
public func call( _ input: Tensor < Scalar > ) -> Tensor < Scalar > {
797
- return input. expandingShape ( at: 1 ) . maxPooled (
797
+ return input. expandingShape ( at: 1 ) . maxPooled2D (
798
798
kernelSize: ( 1 , 1 , poolSize, 1 ) , strides: ( 1 , 1 , stride, 1 ) , padding: padding
799
799
) . squeezingShape ( at: 1 )
800
800
}
@@ -822,15 +822,50 @@ public struct MaxPool2D<Scalar: TensorFlowFloatingPoint>: Layer {
822
822
self . padding = padding
823
823
}
824
824
825
- /// Creates a max pooling layer.
825
+ /// Returns the output obtained from applying the layer to the given input .
826
826
///
827
- /// - Parameters:
828
- /// - poolSize: Vertical and horizontal factors by which to downscale.
829
- /// - strides: The strides.
830
- /// - padding: The padding.
831
- public init ( poolSize: ( Int , Int ) , strides: ( Int , Int ) , padding: Padding = . valid) {
832
- self . poolSize = ( 1 , poolSize. 0 , poolSize. 1 , 1 )
833
- self . strides = ( 1 , strides. 0 , strides. 1 , 1 )
827
+ /// - Parameter input: The input to the layer.
828
+ /// - Returns: The output.
829
+ @differentiable
830
+ public func call( _ input: Tensor < Scalar > ) -> Tensor < Scalar > {
831
+ return input. maxPooled2D (
832
+ kernelSize: poolSize, strides: strides, padding: padding)
833
+ }
834
+ }
835
+
836
+ public extension MaxPool2D {
837
+ /// Creates a max pooling layer.
838
+ ///
839
+ /// - Parameters:
840
+ /// - poolSize: Vertical and horizontal factors by which to downscale.
841
+ /// - strides: The strides.
842
+ /// - padding: The padding.
843
+ init ( poolSize: ( Int , Int ) , strides: ( Int , Int ) , padding: Padding = . valid) {
844
+ self . init ( poolSize: ( 1 , poolSize. 0 , poolSize. 1 , 1 ) ,
845
+ strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
846
+ padding: padding)
847
+ }
848
+ }
849
+
850
+ /// A max pooling layer for spatial or spatio-temporal data.
851
+ @_fixed_layout
852
+ public struct MaxPool3D < Scalar: TensorFlowFloatingPoint > : Layer {
853
+ /// The size of the sliding reduction window for pooling.
854
+ @noDerivative let poolSize : ( Int , Int , Int , Int , Int )
855
+ /// The strides of the sliding window for each dimension of a 5-D input.
856
+ /// Strides in non-spatial dimensions must be `1`.
857
+ @noDerivative let strides : ( Int , Int , Int , Int , Int )
858
+ /// The padding algorithm for pooling.
859
+ @noDerivative let padding : Padding
860
+
861
+ /// Creates a max pooling layer.
862
+ public init (
863
+ poolSize: ( Int , Int , Int , Int , Int ) ,
864
+ strides: ( Int , Int , Int , Int , Int ) ,
865
+ padding: Padding
866
+ ) {
867
+ self . poolSize = poolSize
868
+ self . strides = strides
834
869
self . padding = padding
835
870
}
836
871
@@ -840,11 +875,34 @@ public struct MaxPool2D<Scalar: TensorFlowFloatingPoint>: Layer {
840
875
/// - Returns: The output.
841
876
@differentiable
842
877
public func call( _ input: Tensor < Scalar > ) -> Tensor < Scalar > {
843
- return input. maxPooled (
844
- kernelSize: poolSize, strides: strides, padding: padding)
878
+ return input. maxPooled3D ( kernelSize: poolSize, strides: strides, padding: padding)
845
879
}
846
880
}
847
881
882
+ public extension MaxPool3D {
883
+ /// Creates a max pooling layer.
884
+ ///
885
+ /// - Parameters:
886
+ /// - poolSize: Vertical and horizontal factors by which to downscale.
887
+ /// - strides: The strides.
888
+ /// - padding: The padding.
889
+ init ( poolSize: ( Int , Int , Int ) , strides: ( Int , Int , Int ) , padding: Padding = . valid) {
890
+ self . init ( poolSize: ( 1 , poolSize. 0 , poolSize. 1 , poolSize. 2 , 1 ) ,
891
+ strides: ( 1 , strides. 0 , strides. 1 , strides. 2 , 1 ) ,
892
+ padding: padding)
893
+ }
894
+ }
895
+
896
+ public extension MaxPool3D {
897
+ /// Creates a max pooling layer with the specified pooling window size and stride. All
898
+ /// pooling sizes and strides are the same.
899
+ init ( poolSize: Int , stride: Int , padding: Padding = . valid) {
900
+ self . init ( poolSize: ( poolSize, poolSize, poolSize) ,
901
+ strides: ( stride, stride, stride) ,
902
+ padding: padding)
903
+ }
904
+ }
905
+
848
906
/// An average pooling layer for temporal data.
849
907
@_fixed_layout
850
908
public struct AvgPool1D < Scalar: TensorFlowFloatingPoint > : Layer {
@@ -877,7 +935,7 @@ public struct AvgPool1D<Scalar: TensorFlowFloatingPoint>: Layer {
877
935
/// - Returns: The output.
878
936
@differentiable
879
937
public func call( _ input: Tensor < Scalar > ) -> Tensor < Scalar > {
880
- return input. expandingShape ( at: 1 ) . averagePooled (
938
+ return input. expandingShape ( at: 1 ) . averagePooled2D (
881
939
kernelSize: ( 1 , 1 , poolSize, 1 ) , strides: ( 1 , 1 , stride, 1 ) , padding: padding
882
940
) . squeezingShape ( at: 1 )
883
941
}
@@ -894,7 +952,7 @@ public struct AvgPool2D<Scalar: TensorFlowFloatingPoint>: Layer {
894
952
/// The padding algorithm for pooling.
895
953
@noDerivative let padding : Padding
896
954
897
- /// Creates a average pooling layer.
955
+ /// Creates an average pooling layer.
898
956
public init (
899
957
poolSize: ( Int , Int , Int , Int ) ,
900
958
strides: ( Int , Int , Int , Int ) ,
@@ -905,15 +963,49 @@ public struct AvgPool2D<Scalar: TensorFlowFloatingPoint>: Layer {
905
963
self . padding = padding
906
964
}
907
965
908
- /// Creates a average pooling layer.
966
+ /// Returns the output obtained from applying the layer to the given input .
909
967
///
910
- /// - Parameters:
911
- /// - poolSize: Vertical and horizontal factors by which to downscale.
912
- /// - strides: The strides.
913
- /// - padding: The padding.
914
- public init ( poolSize: ( Int , Int ) , strides: ( Int , Int ) , padding: Padding = . valid) {
915
- self . poolSize = ( 1 , poolSize. 0 , poolSize. 1 , 1 )
916
- self . strides = ( 1 , strides. 0 , strides. 1 , 1 )
968
+ /// - Parameter input: The input to the layer.
969
+ /// - Returns: The output.
970
+ @differentiable
971
+ public func call( _ input: Tensor < Scalar > ) -> Tensor < Scalar > {
972
+ return input. averagePooled2D ( kernelSize: poolSize, strides: strides, padding: padding)
973
+ }
974
+ }
975
+
976
+ public extension AvgPool2D {
977
+ /// Creates an average pooling layer.
978
+ ///
979
+ /// - Parameters:
980
+ /// - poolSize: Vertical and horizontal factors by which to downscale.
981
+ /// - strides: The strides.
982
+ /// - padding: The padding.
983
+ init ( poolSize: ( Int , Int ) , strides: ( Int , Int ) , padding: Padding = . valid) {
984
+ self . init ( poolSize: ( 1 , poolSize. 0 , poolSize. 1 , 1 ) ,
985
+ strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
986
+ padding: padding)
987
+ }
988
+ }
989
+
990
+ /// An average pooling layer for spatial or spatio-temporal data.
991
+ @_fixed_layout
992
+ public struct AvgPool3D < Scalar: TensorFlowFloatingPoint > : Layer {
993
+ /// The size of the sliding reduction window for pooling.
994
+ @noDerivative let poolSize : ( Int , Int , Int , Int , Int )
995
+ /// The strides of the sliding window for each dimension of a 5-D input.
996
+ /// Strides in non-spatial dimensions must be `1`.
997
+ @noDerivative let strides : ( Int , Int , Int , Int , Int )
998
+ /// The padding algorithm for pooling.
999
+ @noDerivative let padding : Padding
1000
+
1001
+ /// Creates an average pooling layer.
1002
+ public init (
1003
+ poolSize: ( Int , Int , Int , Int , Int ) ,
1004
+ strides: ( Int , Int , Int , Int , Int ) ,
1005
+ padding: Padding
1006
+ ) {
1007
+ self . poolSize = poolSize
1008
+ self . strides = strides
917
1009
self . padding = padding
918
1010
}
919
1011
@@ -923,10 +1015,33 @@ public struct AvgPool2D<Scalar: TensorFlowFloatingPoint>: Layer {
923
1015
/// - Returns: The output.
924
1016
@differentiable
925
1017
public func call( _ input: Tensor < Scalar > ) -> Tensor < Scalar > {
926
- return input. averagePooled ( kernelSize: poolSize, strides: strides, padding: padding)
1018
+ return input. averagePooled3D ( kernelSize: poolSize, strides: strides, padding: padding)
927
1019
}
928
1020
}
929
1021
1022
+ public extension AvgPool3D {
1023
+ /// Creates an average pooling layer.
1024
+ ///
1025
+ /// - Parameters:
1026
+ /// - poolSize: Vertical and horizontal factors by which to downscale.
1027
+ /// - strides: The strides.
1028
+ /// - padding: The padding.
1029
+ init ( poolSize: ( Int , Int , Int ) , strides: ( Int , Int , Int ) , padding: Padding = . valid) {
1030
+ self . init ( poolSize: ( 1 , poolSize. 0 , poolSize. 1 , poolSize. 2 , 1 ) ,
1031
+ strides: ( 1 , strides. 0 , strides. 1 , strides. 2 , 1 ) ,
1032
+ padding: padding)
1033
+ }
1034
+ }
1035
+
1036
+ public extension AvgPool3D {
1037
+ /// Creates an average pooling layer with the specified pooling window size and stride. All
1038
+ /// pooling sizes and strides are the same.
1039
+ init ( poolSize: Int , strides: Int , padding: Padding = . valid) {
1040
+ self . init ( poolSize: ( poolSize, poolSize, poolSize) ,
1041
+ strides: ( strides, strides, strides) ,
1042
+ padding: padding)
1043
+ }
1044
+ }
930
1045
931
1046
/// A global average pooling layer for temporal data.
932
1047
@_fixed_layout
0 commit comments