2D convolution with separable filters. Arguments: x: input tensor depthwise_kernel: convolution kernel for the depthwise convolution. pointwise_kernel: kernel for the 1x1 convolution. strides: strides tuple (length 2). padding: string, `"same"` or `"valid"`. da
(x,
depthwise_kernel,
pointwise_kernel,
strides=(1, 1),
padding='valid',
data_format=None,
dilation_rate=(1, 1))
| 4903 | |
| 4904 | @keras_export('keras.backend.separable_conv2d') |
| 4905 | def separable_conv2d(x, |
| 4906 | depthwise_kernel, |
| 4907 | pointwise_kernel, |
| 4908 | strides=(1, 1), |
| 4909 | padding='valid', |
| 4910 | data_format=None, |
| 4911 | dilation_rate=(1, 1)): |
| 4912 | """2D convolution with separable filters. |
| 4913 | |
| 4914 | Arguments: |
| 4915 | x: input tensor |
| 4916 | depthwise_kernel: convolution kernel for the depthwise convolution. |
| 4917 | pointwise_kernel: kernel for the 1x1 convolution. |
| 4918 | strides: strides tuple (length 2). |
| 4919 | padding: string, `"same"` or `"valid"`. |
| 4920 | data_format: string, `"channels_last"` or `"channels_first"`. |
| 4921 | dilation_rate: tuple of integers, |
| 4922 | dilation rates for the separable convolution. |
| 4923 | |
| 4924 | Returns: |
| 4925 | Output tensor. |
| 4926 | |
| 4927 | Raises: |
| 4928 | ValueError: if `data_format` is neither `channels_last` or |
| 4929 | `channels_first`. |
| 4930 | ValueError: if `strides` is not a tuple of 2 integers. |
| 4931 | """ |
| 4932 | if data_format is None: |
| 4933 | data_format = image_data_format() |
| 4934 | if data_format not in {'channels_first', 'channels_last'}: |
| 4935 | raise ValueError('Unknown data_format: ' + str(data_format)) |
| 4936 | if len(strides) != 2: |
| 4937 | raise ValueError('`strides` must be a tuple of 2 integers.') |
| 4938 | |
| 4939 | x, tf_data_format = _preprocess_conv2d_input(x, data_format) |
| 4940 | padding = _preprocess_padding(padding) |
| 4941 | if not isinstance(strides, tuple): |
| 4942 | strides = tuple(strides) |
| 4943 | if tf_data_format == 'NHWC': |
| 4944 | strides = (1,) + strides + (1,) |
| 4945 | else: |
| 4946 | strides = (1, 1) + strides |
| 4947 | |
| 4948 | x = nn.separable_conv2d( |
| 4949 | x, |
| 4950 | depthwise_kernel, |
| 4951 | pointwise_kernel, |
| 4952 | strides=strides, |
| 4953 | padding=padding, |
| 4954 | rate=dilation_rate, |
| 4955 | data_format=tf_data_format) |
| 4956 | if data_format == 'channels_first' and tf_data_format == 'NHWC': |
| 4957 | x = array_ops.transpose(x, (0, 3, 1, 2)) # NHWC -> NCHW |
| 4958 | return x |
| 4959 | |
| 4960 | |
| 4961 | def depthwise_conv2d(x, |
nothing calls this directly
no test coverage detected