Depthwise 2-D convolution. Given a 4D input tensor ('NHWC' or 'NCHW' data formats) and a filter tensor of shape `[filter_height, filter_width, in_channels, channel_multiplier]` containing `in_channels` convolutional filters of depth 1, `depthwise_conv2d` applies a different filter to each
(input,
filter,
strides,
padding,
rate=None,
name=None,
data_format=None,
dilations=None)
| 825 | # pylint: disable=redefined-builtin |
| 826 | @tf_export(v1=["nn.depthwise_conv2d"]) |
| 827 | def depthwise_conv2d(input, |
| 828 | filter, |
| 829 | strides, |
| 830 | padding, |
| 831 | rate=None, |
| 832 | name=None, |
| 833 | data_format=None, |
| 834 | dilations=None): |
| 835 | """Depthwise 2-D convolution. |
| 836 | |
| 837 | Given a 4D input tensor ('NHWC' or 'NCHW' data formats) |
| 838 | and a filter tensor of shape |
| 839 | `[filter_height, filter_width, in_channels, channel_multiplier]` |
| 840 | containing `in_channels` convolutional filters of depth 1, `depthwise_conv2d` |
| 841 | applies a different filter to each input channel (expanding from 1 channel |
| 842 | to `channel_multiplier` channels for each), then concatenates the results |
| 843 | together. The output has `in_channels * channel_multiplier` channels. |
| 844 | |
| 845 | In detail, with the default NHWC format, |
| 846 | |
| 847 | output[b, i, j, k * channel_multiplier + q] = sum_{di, dj} |
| 848 | filter[di, dj, k, q] * input[b, strides[1] * i + rate[0] * di, |
| 849 | strides[2] * j + rate[1] * dj, k] |
| 850 | |
| 851 | Must have `strides[0] = strides[3] = 1`. For the most common case of the |
| 852 | same horizontal and vertical strides, `strides = [1, stride, stride, 1]`. |
| 853 | If any value in `rate` is greater than 1, we perform atrous depthwise |
| 854 | convolution, in which case all values in the `strides` tensor must be equal |
| 855 | to 1. |
| 856 | |
| 857 | Args: |
| 858 | input: 4-D with shape according to `data_format`. |
| 859 | filter: 4-D with shape |
| 860 | `[filter_height, filter_width, in_channels, channel_multiplier]`. |
| 861 | strides: 1-D of size 4. The stride of the sliding window for each |
| 862 | dimension of `input`. |
| 863 | padding: A string, either `'VALID'` or `'SAME'`. The padding algorithm. |
| 864 | See the "returns" section of `tf.nn.convolution` for details. |
| 865 | rate: 1-D of size 2. The dilation rate in which we sample input values |
| 866 | across the `height` and `width` dimensions in atrous convolution. If it is |
| 867 | greater than 1, then all values of strides must be 1. |
| 868 | name: A name for this operation (optional). |
| 869 | data_format: The data format for input. Either "NHWC" (default) or "NCHW". |
| 870 | dilations: Alias of rate. |
| 871 | |
| 872 | Returns: |
| 873 | A 4-D `Tensor` with shape according to `data_format`. E.g., for |
| 874 | "NHWC" format, shape is |
| 875 | `[batch, out_height, out_width, in_channels * channel_multiplier].` |
| 876 | """ |
| 877 | rate = deprecated_argument_lookup("dilations", dilations, "rate", rate) |
| 878 | with ops.name_scope(name, "depthwise", [input, filter]) as name: |
| 879 | input = ops.convert_to_tensor(input, name="tensor_in") |
| 880 | filter = ops.convert_to_tensor(filter, name="filter_in") |
| 881 | if rate is None: |
| 882 | rate = [1, 1] |
| 883 | |
| 884 | # copybara:strip_begin |
no test coverage detected