@@ -708,6 +708,8 @@ public struct DepthwiseConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
708
708
@noDerivative public let strides : ( Int , Int )
709
709
/// The padding algorithm for convolution.
710
710
@noDerivative public let padding : Padding
711
+ /// The dilation factor for spatial dimensions.
712
+ @noDerivative public let dilations : ( Int , Int )
711
713
/// Note: `useBias` is a workaround for TF-1153: optional differentiation support.
712
714
@noDerivative private let useBias : Bool
713
715
@@ -723,18 +725,21 @@ public struct DepthwiseConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
723
725
/// - activation: The element-wise activation function.
724
726
/// - strides: The strides of the sliding window for spatial dimensions.
725
727
/// - padding: The padding algorithm for convolution.
728
+ /// - dilations: The dilation factors for spatial dimensions.
726
729
public init (
727
730
filter: Tensor < Scalar > ,
728
731
bias: Tensor < Scalar > ? = nil ,
729
732
activation: @escaping Activation = identity,
730
733
strides: ( Int , Int ) = ( 1 , 1 ) ,
731
- padding: Padding = . valid
734
+ padding: Padding = . valid,
735
+ dilations: ( Int , Int ) = ( 1 , 1 )
732
736
) {
733
737
self . filter = filter
734
738
self . bias = bias ?? . zero
735
739
self . activation = activation
736
740
self . strides = strides
737
741
self . padding = padding
742
+ self . dilations = dilations
738
743
useBias = ( bias != nil )
739
744
}
740
745
@@ -750,7 +755,8 @@ public struct DepthwiseConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
750
755
input,
751
756
filter: filter,
752
757
strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
753
- padding: padding)
758
+ padding: padding,
759
+ dilations: ( 1 , dilations. 0 , dilations. 1 , 1 ) )
754
760
return activation ( useBias ? ( conv + bias) : conv)
755
761
}
756
762
}
@@ -771,6 +777,7 @@ extension DepthwiseConv2D {
771
777
filterShape: ( Int , Int , Int , Int ) ,
772
778
strides: ( Int , Int ) = ( 1 , 1 ) ,
773
779
padding: Padding = . valid,
780
+ dilations: ( Int , Int ) = ( 1 , 1 ) ,
774
781
activation: @escaping Activation = identity,
775
782
useBias: Bool = true ,
776
783
filterInitializer: ParameterInitializer < Scalar > = glorotUniform ( ) ,
@@ -784,7 +791,8 @@ extension DepthwiseConv2D {
784
791
bias: useBias ? biasInitializer ( [ filterShape. 2 * filterShape. 3 ] ) : nil ,
785
792
activation: activation,
786
793
strides: strides,
787
- padding: padding)
794
+ padding: padding,
795
+ dilations: dilations)
788
796
}
789
797
}
790
798
@@ -901,12 +909,15 @@ public struct SeparableConv1D<Scalar: TensorFlowFloatingPoint>: Layer {
901
909
public var pointwiseFilter : Tensor < Scalar >
902
910
/// The bias vector.
903
911
public var bias : Tensor < Scalar >
912
+
904
913
/// The element-wise activation function.
905
914
@noDerivative public let activation : Activation
906
915
/// The strides of the sliding window for spatial dimensions.
907
916
@noDerivative public let stride : Int
908
917
/// The padding algorithm for convolution.
909
918
@noDerivative public let padding : Padding
919
+ /// The dilation factor for the temporal dimension.
920
+ @noDerivative public let dilation : Int
910
921
/// Note: `useBias` is a workaround for TF-1153: optional differentiation support.
911
922
@noDerivative private let useBias : Bool
912
923
@@ -925,20 +936,23 @@ public struct SeparableConv1D<Scalar: TensorFlowFloatingPoint>: Layer {
925
936
/// - activation: The element-wise activation function.
926
937
/// - strides: The strides of the sliding window for spatial dimensions.
927
938
/// - padding: The padding algorithm for convolution.
939
+ /// - dilation: The dilation factor for the temporal dimension.
928
940
public init (
929
941
depthwiseFilter: Tensor < Scalar > ,
930
942
pointwiseFilter: Tensor < Scalar > ,
931
943
bias: Tensor < Scalar > ? = nil ,
932
944
activation: @escaping Activation = identity,
933
945
stride: Int = 1 ,
934
- padding: Padding = . valid
946
+ padding: Padding = . valid,
947
+ dilation: Int = 1
935
948
) {
936
949
self . depthwiseFilter = depthwiseFilter
937
950
self . pointwiseFilter = pointwiseFilter
938
951
self . bias = bias ?? . zero
939
952
self . activation = activation
940
953
self . stride = stride
941
954
self . padding = padding
955
+ self . dilation = dilation
942
956
useBias = ( bias != nil )
943
957
}
944
958
@@ -952,7 +966,8 @@ public struct SeparableConv1D<Scalar: TensorFlowFloatingPoint>: Layer {
952
966
input. expandingShape ( at: 1 ) ,
953
967
filter: depthwiseFilter. expandingShape ( at: 1 ) ,
954
968
strides: ( 1 , stride, stride, 1 ) ,
955
- padding: padding)
969
+ padding: padding,
970
+ dilations: ( 1 , dilation, dilation, 1 ) )
956
971
let x = conv2D (
957
972
depthwise,
958
973
filter: pointwiseFilter. expandingShape ( at: 1 ) ,
@@ -970,8 +985,9 @@ extension SeparableConv1D {
970
985
/// - Parameters:
971
986
/// - depthwiseFilterShape: The shape of the 3-D depthwise convolution kernel.
972
987
/// - pointwiseFilterShape: The shape of the 3-D pointwise convolution kernel.
973
- /// - strides : The strides of the sliding window for temporal dimensions.
988
+ /// - stride : The stride of the sliding window for temporal dimensions.
974
989
/// - padding: The padding algorithm for convolution.
990
+ /// - dilation: The dilation factor for the temporal dimension.
975
991
/// - activation: The element-wise activation function.
976
992
/// - filterInitializer: Initializer to use for the filter parameters.
977
993
/// - biasInitializer: Initializer to use for the bias parameters.
@@ -980,6 +996,7 @@ extension SeparableConv1D {
980
996
pointwiseFilterShape: ( Int , Int , Int ) ,
981
997
stride: Int = 1 ,
982
998
padding: Padding = . valid,
999
+ dilation: Int = 1 ,
983
1000
activation: @escaping Activation = identity,
984
1001
useBias: Bool = true ,
985
1002
depthwiseFilterInitializer: ParameterInitializer < Scalar > = glorotUniform ( ) ,
@@ -998,7 +1015,8 @@ extension SeparableConv1D {
998
1015
bias: useBias ? biasInitializer ( [ pointwiseFilterShape. 2 ] ) : nil ,
999
1016
activation: activation,
1000
1017
stride: stride,
1001
- padding: padding)
1018
+ padding: padding,
1019
+ dilation: dilation)
1002
1020
}
1003
1021
}
1004
1022
@@ -1020,6 +1038,8 @@ public struct SeparableConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
1020
1038
@noDerivative public let strides : ( Int , Int )
1021
1039
/// The padding algorithm for convolution.
1022
1040
@noDerivative public let padding : Padding
1041
+ /// The dilation factor for spatial dimensions.
1042
+ @noDerivative public let dilations : ( Int , Int )
1023
1043
/// Note: `useBias` is a workaround for TF-1153: optional differentiation support.
1024
1044
@noDerivative private let useBias : Bool
1025
1045
@@ -1038,20 +1058,23 @@ public struct SeparableConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
1038
1058
/// - activation: The element-wise activation function.
1039
1059
/// - strides: The strides of the sliding window for spatial dimensions.
1040
1060
/// - padding: The padding algorithm for convolution.
1061
+ /// - dilations: The dilation factors for spatial dimensions.
1041
1062
public init (
1042
1063
depthwiseFilter: Tensor < Scalar > ,
1043
1064
pointwiseFilter: Tensor < Scalar > ,
1044
1065
bias: Tensor < Scalar > ? = nil ,
1045
1066
activation: @escaping Activation = identity,
1046
1067
strides: ( Int , Int ) = ( 1 , 1 ) ,
1047
- padding: Padding = . valid
1068
+ padding: Padding = . valid,
1069
+ dilations: ( Int , Int ) = ( 1 , 1 )
1048
1070
) {
1049
1071
self . depthwiseFilter = depthwiseFilter
1050
1072
self . pointwiseFilter = pointwiseFilter
1051
1073
self . bias = bias ?? . zero
1052
1074
self . activation = activation
1053
1075
self . strides = strides
1054
1076
self . padding = padding
1077
+ self . dilations = dilations
1055
1078
useBias = ( bias != nil )
1056
1079
}
1057
1080
@@ -1065,7 +1088,8 @@ public struct SeparableConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
1065
1088
input,
1066
1089
filter: depthwiseFilter,
1067
1090
strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
1068
- padding: padding)
1091
+ padding: padding,
1092
+ dilations: ( 1 , dilations. 0 , dilations. 1 , 1 ) )
1069
1093
let conv = conv2D (
1070
1094
depthwise,
1071
1095
filter: pointwiseFilter,
@@ -1085,6 +1109,7 @@ extension SeparableConv2D {
1085
1109
/// - pointwiseFilterShape: The shape of the 4-D pointwise convolution kernel.
1086
1110
/// - strides: The strides of the sliding window for spatial/spatio-temporal dimensions.
1087
1111
/// - padding: The padding algorithm for convolution.
1112
+ /// - dilations: The dilation factors for spatial dimensions.
1088
1113
/// - activation: The element-wise activation function.
1089
1114
/// - filterInitializer: Initializer to use for the filter parameters.
1090
1115
/// - biasInitializer: Initializer to use for the bias parameters.
@@ -1093,6 +1118,7 @@ extension SeparableConv2D {
1093
1118
pointwiseFilterShape: ( Int , Int , Int , Int ) ,
1094
1119
strides: ( Int , Int ) = ( 1 , 1 ) ,
1095
1120
padding: Padding = . valid,
1121
+ dilations: ( Int , Int ) = ( 1 , 1 ) ,
1096
1122
activation: @escaping Activation = identity,
1097
1123
useBias: Bool = true ,
1098
1124
depthwiseFilterInitializer: ParameterInitializer < Scalar > = glorotUniform ( ) ,
@@ -1113,6 +1139,7 @@ extension SeparableConv2D {
1113
1139
bias: useBias ? biasInitializer ( [ pointwiseFilterShape. 3 ] ) : nil ,
1114
1140
activation: activation,
1115
1141
strides: strides,
1116
- padding: padding)
1142
+ padding: padding,
1143
+ dilations: dilations)
1117
1144
}
1118
1145
}
0 commit comments