@@ -708,6 +708,8 @@ public struct DepthwiseConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
708708 @noDerivative public let strides : ( Int , Int )
709709 /// The padding algorithm for convolution.
710710 @noDerivative public let padding : Padding
711+ /// The dilation factor for spatial dimensions.
712+ @noDerivative public let dilations : ( Int , Int )
711713 /// Note: `useBias` is a workaround for TF-1153: optional differentiation support.
712714 @noDerivative private let useBias : Bool
713715
@@ -723,18 +725,21 @@ public struct DepthwiseConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
723725 /// - activation: The element-wise activation function.
724726 /// - strides: The strides of the sliding window for spatial dimensions.
725727 /// - padding: The padding algorithm for convolution.
728+ /// - dilations: The dilation factors for spatial dimensions.
726729 public init (
727730 filter: Tensor < Scalar > ,
728731 bias: Tensor < Scalar > ? = nil ,
729732 activation: @escaping Activation = identity,
730733 strides: ( Int , Int ) = ( 1 , 1 ) ,
731- padding: Padding = . valid
734+ padding: Padding = . valid,
735+ dilations: ( Int , Int ) = ( 1 , 1 )
732736 ) {
733737 self . filter = filter
734738 self . bias = bias ?? . zero
735739 self . activation = activation
736740 self . strides = strides
737741 self . padding = padding
742+ self . dilations = dilations
738743 useBias = ( bias != nil )
739744 }
740745
@@ -750,7 +755,8 @@ public struct DepthwiseConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
750755 input,
751756 filter: filter,
752757 strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
753- padding: padding)
758+ padding: padding,
759+ dilations: ( 1 , dilations. 0 , dilations. 1 , 1 ) )
754760 return activation ( useBias ? ( conv + bias) : conv)
755761 }
756762}
@@ -771,6 +777,7 @@ extension DepthwiseConv2D {
771777 filterShape: ( Int , Int , Int , Int ) ,
772778 strides: ( Int , Int ) = ( 1 , 1 ) ,
773779 padding: Padding = . valid,
780+ dilations: ( Int , Int ) = ( 1 , 1 ) ,
774781 activation: @escaping Activation = identity,
775782 useBias: Bool = true ,
776783 filterInitializer: ParameterInitializer < Scalar > = glorotUniform ( ) ,
@@ -784,7 +791,8 @@ extension DepthwiseConv2D {
784791 bias: useBias ? biasInitializer ( [ filterShape. 2 * filterShape. 3 ] ) : nil ,
785792 activation: activation,
786793 strides: strides,
787- padding: padding)
794+ padding: padding,
795+ dilations: dilations)
788796 }
789797}
790798
@@ -901,12 +909,15 @@ public struct SeparableConv1D<Scalar: TensorFlowFloatingPoint>: Layer {
901909 public var pointwiseFilter : Tensor < Scalar >
902910 /// The bias vector.
903911 public var bias : Tensor < Scalar >
912+
904913 /// The element-wise activation function.
905914 @noDerivative public let activation : Activation
906915 /// The strides of the sliding window for spatial dimensions.
907916 @noDerivative public let stride : Int
908917 /// The padding algorithm for convolution.
909918 @noDerivative public let padding : Padding
919+ /// The dilation factor for the temporal dimension.
920+ @noDerivative public let dilation : Int
910921 /// Note: `useBias` is a workaround for TF-1153: optional differentiation support.
911922 @noDerivative private let useBias : Bool
912923
@@ -925,20 +936,23 @@ public struct SeparableConv1D<Scalar: TensorFlowFloatingPoint>: Layer {
925936 /// - activation: The element-wise activation function.
926937 /// - strides: The strides of the sliding window for spatial dimensions.
927938 /// - padding: The padding algorithm for convolution.
939+ /// - dilation: The dilation factor for the temporal dimension.
928940 public init (
929941 depthwiseFilter: Tensor < Scalar > ,
930942 pointwiseFilter: Tensor < Scalar > ,
931943 bias: Tensor < Scalar > ? = nil ,
932944 activation: @escaping Activation = identity,
933945 stride: Int = 1 ,
934- padding: Padding = . valid
946+ padding: Padding = . valid,
947+ dilation: Int = 1
935948 ) {
936949 self . depthwiseFilter = depthwiseFilter
937950 self . pointwiseFilter = pointwiseFilter
938951 self . bias = bias ?? . zero
939952 self . activation = activation
940953 self . stride = stride
941954 self . padding = padding
955+ self . dilation = dilation
942956 useBias = ( bias != nil )
943957 }
944958
@@ -952,7 +966,8 @@ public struct SeparableConv1D<Scalar: TensorFlowFloatingPoint>: Layer {
952966 input. expandingShape ( at: 1 ) ,
953967 filter: depthwiseFilter. expandingShape ( at: 1 ) ,
954968 strides: ( 1 , stride, stride, 1 ) ,
955- padding: padding)
969+ padding: padding,
970+ dilations: ( 1 , dilation, dilation, 1 ) )
956971 let x = conv2D (
957972 depthwise,
958973 filter: pointwiseFilter. expandingShape ( at: 1 ) ,
@@ -970,8 +985,9 @@ extension SeparableConv1D {
970985 /// - Parameters:
971986 /// - depthwiseFilterShape: The shape of the 3-D depthwise convolution kernel.
972987 /// - 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.
974989 /// - padding: The padding algorithm for convolution.
990+ /// - dilation: The dilation factor for the temporal dimension.
975991 /// - activation: The element-wise activation function.
976992 /// - filterInitializer: Initializer to use for the filter parameters.
977993 /// - biasInitializer: Initializer to use for the bias parameters.
@@ -980,6 +996,7 @@ extension SeparableConv1D {
980996 pointwiseFilterShape: ( Int , Int , Int ) ,
981997 stride: Int = 1 ,
982998 padding: Padding = . valid,
999+ dilation: Int = 1 ,
9831000 activation: @escaping Activation = identity,
9841001 useBias: Bool = true ,
9851002 depthwiseFilterInitializer: ParameterInitializer < Scalar > = glorotUniform ( ) ,
@@ -998,7 +1015,8 @@ extension SeparableConv1D {
9981015 bias: useBias ? biasInitializer ( [ pointwiseFilterShape. 2 ] ) : nil ,
9991016 activation: activation,
10001017 stride: stride,
1001- padding: padding)
1018+ padding: padding,
1019+ dilation: dilation)
10021020 }
10031021}
10041022
@@ -1020,6 +1038,8 @@ public struct SeparableConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
10201038 @noDerivative public let strides : ( Int , Int )
10211039 /// The padding algorithm for convolution.
10221040 @noDerivative public let padding : Padding
1041+ /// The dilation factor for spatial dimensions.
1042+ @noDerivative public let dilations : ( Int , Int )
10231043 /// Note: `useBias` is a workaround for TF-1153: optional differentiation support.
10241044 @noDerivative private let useBias : Bool
10251045
@@ -1038,20 +1058,23 @@ public struct SeparableConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
10381058 /// - activation: The element-wise activation function.
10391059 /// - strides: The strides of the sliding window for spatial dimensions.
10401060 /// - padding: The padding algorithm for convolution.
1061+ /// - dilations: The dilation factors for spatial dimensions.
10411062 public init (
10421063 depthwiseFilter: Tensor < Scalar > ,
10431064 pointwiseFilter: Tensor < Scalar > ,
10441065 bias: Tensor < Scalar > ? = nil ,
10451066 activation: @escaping Activation = identity,
10461067 strides: ( Int , Int ) = ( 1 , 1 ) ,
1047- padding: Padding = . valid
1068+ padding: Padding = . valid,
1069+ dilations: ( Int , Int ) = ( 1 , 1 )
10481070 ) {
10491071 self . depthwiseFilter = depthwiseFilter
10501072 self . pointwiseFilter = pointwiseFilter
10511073 self . bias = bias ?? . zero
10521074 self . activation = activation
10531075 self . strides = strides
10541076 self . padding = padding
1077+ self . dilations = dilations
10551078 useBias = ( bias != nil )
10561079 }
10571080
@@ -1065,7 +1088,8 @@ public struct SeparableConv2D<Scalar: TensorFlowFloatingPoint>: Layer {
10651088 input,
10661089 filter: depthwiseFilter,
10671090 strides: ( 1 , strides. 0 , strides. 1 , 1 ) ,
1068- padding: padding)
1091+ padding: padding,
1092+ dilations: ( 1 , dilations. 0 , dilations. 1 , 1 ) )
10691093 let conv = conv2D (
10701094 depthwise,
10711095 filter: pointwiseFilter,
@@ -1085,6 +1109,7 @@ extension SeparableConv2D {
10851109 /// - pointwiseFilterShape: The shape of the 4-D pointwise convolution kernel.
10861110 /// - strides: The strides of the sliding window for spatial/spatio-temporal dimensions.
10871111 /// - padding: The padding algorithm for convolution.
1112+ /// - dilations: The dilation factors for spatial dimensions.
10881113 /// - activation: The element-wise activation function.
10891114 /// - filterInitializer: Initializer to use for the filter parameters.
10901115 /// - biasInitializer: Initializer to use for the bias parameters.
@@ -1093,6 +1118,7 @@ extension SeparableConv2D {
10931118 pointwiseFilterShape: ( Int , Int , Int , Int ) ,
10941119 strides: ( Int , Int ) = ( 1 , 1 ) ,
10951120 padding: Padding = . valid,
1121+ dilations: ( Int , Int ) = ( 1 , 1 ) ,
10961122 activation: @escaping Activation = identity,
10971123 useBias: Bool = true ,
10981124 depthwiseFilterInitializer: ParameterInitializer < Scalar > = glorotUniform ( ) ,
@@ -1113,6 +1139,7 @@ extension SeparableConv2D {
11131139 bias: useBias ? biasInitializer ( [ pointwiseFilterShape. 3 ] ) : nil ,
11141140 activation: activation,
11151141 strides: strides,
1116- padding: padding)
1142+ padding: padding,
1143+ dilations: dilations)
11171144 }
11181145}
0 commit comments