2D convolution with separable filters. Arguments: x: input tensor depthwise_kernel: convolution kernel for the depthwise convolution. strides: strides tuple (length 2). padding: string, `"same"` or `"valid"`. data_format: string, `"channels_last"` or `"channels_first
(x,
depthwise_kernel,
strides=(1, 1),
padding='valid',
data_format=None,
dilation_rate=(1, 1))
| 4959 | |
| 4960 | |
| 4961 | def depthwise_conv2d(x, |
| 4962 | depthwise_kernel, |
| 4963 | strides=(1, 1), |
| 4964 | padding='valid', |
| 4965 | data_format=None, |
| 4966 | dilation_rate=(1, 1)): |
| 4967 | """2D convolution with separable filters. |
| 4968 | |
| 4969 | Arguments: |
| 4970 | x: input tensor |
| 4971 | depthwise_kernel: convolution kernel for the depthwise convolution. |
| 4972 | strides: strides tuple (length 2). |
| 4973 | padding: string, `"same"` or `"valid"`. |
| 4974 | data_format: string, `"channels_last"` or `"channels_first"`. |
| 4975 | dilation_rate: tuple of integers, |
| 4976 | dilation rates for the separable convolution. |
| 4977 | |
| 4978 | Returns: |
| 4979 | Output tensor. |
| 4980 | |
| 4981 | Raises: |
| 4982 | ValueError: if `data_format` is neither `channels_last` or |
| 4983 | `channels_first`. |
| 4984 | """ |
| 4985 | if data_format is None: |
| 4986 | data_format = image_data_format() |
| 4987 | if data_format not in {'channels_first', 'channels_last'}: |
| 4988 | raise ValueError('Unknown data_format: ' + str(data_format)) |
| 4989 | |
| 4990 | x, tf_data_format = _preprocess_conv2d_input(x, data_format) |
| 4991 | padding = _preprocess_padding(padding) |
| 4992 | if tf_data_format == 'NHWC': |
| 4993 | strides = (1,) + strides + (1,) |
| 4994 | else: |
| 4995 | strides = (1, 1) + strides |
| 4996 | |
| 4997 | x = nn.depthwise_conv2d( |
| 4998 | x, |
| 4999 | depthwise_kernel, |
| 5000 | strides=strides, |
| 5001 | padding=padding, |
| 5002 | rate=dilation_rate, |
| 5003 | data_format=tf_data_format) |
| 5004 | if data_format == 'channels_first' and tf_data_format == 'NHWC': |
| 5005 | x = array_ops.transpose(x, (0, 3, 1, 2)) # NHWC -> NCHW |
| 5006 | return x |
| 5007 | |
| 5008 | |
| 5009 | @keras_export('keras.backend.conv3d') |
nothing calls this directly
no test coverage detected