@@ -828,11 +828,9 @@ public struct MaxPool2D<Scalar: TensorFlowFloatingPoint>: Layer {
828
828
/// - poolSize: Vertical and horizontal factors by which to downscale.
829
829
/// - strides: The strides.
830
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 )
834
- self . padding = padding
835
- }
831
+ self. init( poolSize: ( 1 , poolSize. 0 , poolSize. 1 , 1 ) ,
832
+ strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
833
+ padding: padding)
836
834
837
835
/// Returns the output obtained from applying the layer to the given input.
838
836
///
@@ -845,6 +843,58 @@ public struct MaxPool2D<Scalar: TensorFlowFloatingPoint>: Layer {
845
843
}
846
844
}
847
845
846
+ /// A max pooling layer for spatial or spatio-temporal data.
847
+ @_fixed_layout
848
+ public struct MaxPool3D < Scalar: TensorFlowFloatingPoint > : Layer {
849
+ /// The size of the sliding reduction window for pooling.
850
+ @noDerivative let poolSize : ( Int , Int , Int , Int , Int )
851
+ /// The strides of the sliding window for each dimension of a 5-D input.
852
+ /// Strides in non-spatial dimensions must be `1`.
853
+ @noDerivative let strides : ( Int , Int , Int , Int , Int )
854
+ /// The padding algorithm for pooling.
855
+ @noDerivative let padding : Padding
856
+
857
+ /// Creates a max pooling layer.
858
+ public init (
859
+ poolSize: ( Int , Int , Int , Int , Int ) ,
860
+ strides: ( Int , Int , Int , Int , Int ) ,
861
+ padding: Padding
862
+ ) {
863
+ self . poolSize = poolSize
864
+ self . strides = strides
865
+ self . padding = padding
866
+ }
867
+
868
+ /// Creates a max pooling layer.
869
+ ///
870
+ /// - Parameters:
871
+ /// - poolSize: Vertical and horizontal factors by which to downscale.
872
+ /// - strides: The strides.
873
+ /// - padding: The padding.
874
+ self. init( poolSize: ( 1 , poolSize. 0 , poolSize. 1 , poolSize. 2 , 1 ) ,
875
+ strides: ( 1 , strides. 0 , strides. 1 , strides. 2 , 1 ) ,
876
+ padding: padding)
877
+
878
+ /// Returns the output obtained from applying the layer to the given input.
879
+ ///
880
+ /// - Parameter input: The input to the layer.
881
+ /// - Returns: The output.
882
+ @differentiable
883
+ public func call( _ input: Tensor < Scalar > ) -> Tensor < Scalar > {
884
+ return input. maxPooled ( kernelSize: poolSize, strides: strides, padding: padding)
885
+ }
886
+ }
887
+
888
+ public extension MaxPool3D {
889
+ /// Creates a max pooling layer with the specified pooling window size and stride. All
890
+ /// pooling sizes and strides are the same.
891
+ init ( poolSize: Int , stride: Int , padding: Padding = . valid) {
892
+ self . init ( poolsize: ( poolSize, poolSize, poolSize) ,
893
+ strides: ( stride, stride, stride) ,
894
+ padding: padding)
895
+ }
896
+ }
897
+
848
898
/// An average pooling layer for temporal data.
849
899
@_fixed_layout
850
900
public struct AvgPool1D < Scalar: TensorFlowFloatingPoint > : Layer {
@@ -894,7 +944,7 @@ public struct AvgPool2D<Scalar: TensorFlowFloatingPoint>: Layer {
894
944
/// The padding algorithm for pooling.
895
945
@noDerivative let padding : Padding
896
946
897
- /// Creates a average pooling layer.
947
+ /// Creates an average pooling layer.
898
948
public init (
899
949
poolSize: ( Int , Int , Int , Int ) ,
900
950
strides: ( Int , Int , Int , Int ) ,
@@ -905,18 +955,58 @@ public struct AvgPool2D<Scalar: TensorFlowFloatingPoint>: Layer {
905
955
self . padding = padding
906
956
}
907
957
908
- /// Creates a average pooling layer.
958
+ /// Creates an average pooling layer.
909
959
///
910
960
/// - Parameters:
911
961
/// - poolSize: Vertical and horizontal factors by which to downscale.
912
962
/// - strides: The strides.
913
963
/// - 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 )
964
+ self. init( poolSize: ( 1 , poolSize. 0 , poolSize. 1 , 1 ) ,
965
+ strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
966
+ padding: padding)
967
+
968
+ /// Returns the output obtained from applying the layer to the given input.
969
+ ///
970
+ /// - Parameter input: The input to the layer.
971
+ /// - Returns: The output.
972
+ @differentiable
973
+ public func call( _ input: Tensor < Scalar > ) -> Tensor < Scalar > {
974
+ return input. averagePooled ( kernelSize: poolSize, strides: strides, padding: padding)
975
+ }
976
+ }
977
+
978
+ /// An average pooling layer for spatial or spatio-temporal data.
979
+ @_fixed_layout
980
+ public struct AvgPool3D < Scalar: TensorFlowFloatingPoint > : Layer {
981
+ /// The size of the sliding reduction window for pooling.
982
+ @noDerivative let poolSize : ( Int , Int , Int , Int , Int )
983
+ /// The strides of the sliding window for each dimension of a 5-D input.
984
+ /// Strides in non-spatial dimensions must be `1`.
985
+ @noDerivative let strides : ( Int , Int , Int , Int , Int )
986
+ /// The padding algorithm for pooling.
987
+ @noDerivative let padding : Padding
988
+
989
+ /// Creates an average pooling layer.
990
+ public init (
991
+ poolSize: ( Int , Int , Int , Int , Int ) ,
992
+ strides: ( Int , Int , Int , Int , Int ) ,
993
+ padding: Padding
994
+ ) {
995
+ self . poolSize = poolSize
996
+ self . strides = strides
917
997
self . padding = padding
918
998
}
919
999
1000
+ /// Creates an average pooling layer.
1001
+ ///
1002
+ /// - Parameters:
1003
+ /// - poolSize: Vertical and horizontal factors by which to downscale.
1004
+ /// - strides: The strides.
1005
+ /// - padding: The padding.
1006
+ self. init( poolSize: ( 1 , poolSize. 0 , poolSize. 1 , poolSize. 2 , 1 ) ,
1007
+ strides: ( 1 , strides. 0 , strides. 1 , strides. 2 , 1 ) ,
1008
+ padding: padding)
1009
+
920
1010
/// Returns the output obtained from applying the layer to the given input.
921
1011
///
922
1012
/// - Parameter input: The input to the layer.
@@ -927,6 +1017,15 @@ public struct AvgPool2D<Scalar: TensorFlowFloatingPoint>: Layer {
927
1017
}
928
1018
}
929
1019
1020
+ public extension AvgPool3D {
1021
+ /// Creates an average pooling layer with the specified pooling window size and stride. All
1022
+ /// pooling sizes and strides are the same.
1023
+ init ( poolSize: Int , strides: Int , padding: Padding = . valid) {
1024
+ self . init ( poolSize: ( poolSize, poolSize, poolSize) ,
1025
+ strides: ( strides, strides, strides) ,
1026
+ padding: padding)
1027
+ }
1028
+ }
930
1029
931
1030
/// A global average pooling layer for temporal data.
932
1031
@_fixed_layout
0 commit comments