tf.compat.v1.nn.depthwise_conv2d
Stay organized with collections
Save and categorize content based on your preferences.
Depthwise 2-D convolution.
tf.compat.v1.nn.depthwise_conv2d(
input,
filter,
strides,
padding,
rate=None,
name=None,
data_format=None,
dilations=None
)
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 channel (expanding from 1 channel
to channel_multiplier
channels for each), then concatenates the results
together. The output has in_channels * channel_multiplier
channels.
In detail, with the default NHWC format,
output[b, i, j, k * channel_multiplier + q] = sum_{di, dj}
filter[di, dj, k, q] * input[b, strides[1] * i + rate[0] * di,
strides[2] * j + rate[1] * dj, k]
Must have strides[0] = strides[3] = 1
. For the most common case of the
same horizontal and vertical strides, strides = [1, stride, stride, 1]
.
If any value in rate
is greater than 1, we perform atrous depthwise
convolution, in which case all values in the strides
tensor must be equal
to 1.
Usage Example:
x = np.array([
[1., 2.],
[3., 4.],
[5., 6.]
], dtype=np.float32).reshape((1, 3, 2, 1))
kernel = np.array([
[1., 2.],
[3., 4]
], dtype=np.float32).reshape((2, 1, 1, 2))
tf.compat.v1.nn.depthwise_conv2d(x, kernel, strides=[1, 1, 1, 1],
padding='VALID').numpy()
array([[[[10., 14.],
[14., 20.]],
[[18., 26.],
[22., 32.]]]], dtype=float32)
tf.compat.v1.nn.depthwise_conv2d(x, kernel, strides=[1, 1, 1, 1],
padding=[[0, 0], [1, 0], [1, 0], [0, 0]]
).numpy()
array([[[[ 0., 0.],
[ 3., 4.],
[ 6., 8.]],
[[ 0., 0.],
[10., 14.],
[14., 20.]],
[[ 0., 0.],
[18., 26.],
[22., 32.]]]], dtype=float32)
Args |
input
|
4-D with shape according to data_format .
|
filter
|
4-D with shape
[filter_height, filter_width, in_channels, channel_multiplier] .
|
strides
|
1-D of size 4. The stride of the sliding window for each
dimension of input .
|
padding
|
Controls how to pad the image before applying the convolution. Can
be the string "SAME" or "VALID" indicating the type of padding
algorithm to use, or a list indicating the explicit paddings at the start
and end of each dimension. When explicit padding is used and data_format
is "NHWC" , this should be in the form [[0, 0], [pad_top, pad_bottom],
[pad_left, pad_right], [0, 0]] . When explicit padding used and
data_format is "NCHW" , this should be in the form [[0, 0], [0, 0],
[pad_top, pad_bottom], [pad_left, pad_right]] .
|
rate
|
1-D of size 2. The dilation rate in which we sample input values
across the height and width dimensions in atrous convolution. If it is
greater than 1, then all values of strides must be 1.
|
name
|
A name for this operation (optional).
|
data_format
|
The data format for input. Either "NHWC" (default) or "NCHW".
|
dilations
|
Alias of rate.
|
Returns |
A 4-D Tensor with shape according to data_format . E.g., for
"NHWC" format, shape is
[batch, out_height, out_width, in_channels * channel_multiplier].
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2024-04-26 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.compat.v1.nn.depthwise_conv2d\n\n\u003cbr /\u003e\n\n|---------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/nn_impl.py#L663-L789) |\n\nDepthwise 2-D convolution. \n\n tf.compat.v1.nn.depthwise_conv2d(\n input,\n filter,\n strides,\n padding,\n rate=None,\n name=None,\n data_format=None,\n dilations=None\n )\n\nGiven a 4D input tensor ('NHWC' or 'NCHW' data formats)\nand a filter tensor of shape\n`[filter_height, filter_width, in_channels, channel_multiplier]`\ncontaining `in_channels` convolutional filters of depth 1, `depthwise_conv2d`\napplies a different filter to each input channel (expanding from 1 channel\nto `channel_multiplier` channels for each), then concatenates the results\ntogether. The output has `in_channels * channel_multiplier` channels.\n\nIn detail, with the default NHWC format, \n\n output[b, i, j, k * channel_multiplier + q] = sum_{di, dj}\n filter[di, dj, k, q] * input[b, strides[1] * i + rate[0] * di,\n strides[2] * j + rate[1] * dj, k]\n\nMust have `strides[0] = strides[3] = 1`. For the most common case of the\nsame horizontal and vertical strides, `strides = [1, stride, stride, 1]`.\nIf any value in `rate` is greater than 1, we perform atrous depthwise\nconvolution, in which case all values in the `strides` tensor must be equal\nto 1.\n\n#### Usage Example:\n\n x = np.array([\n [1., 2.],\n [3., 4.],\n [5., 6.]\n ], dtype=np.float32).reshape((1, 3, 2, 1))\n kernel = np.array([\n [1., 2.],\n [3., 4]\n ], dtype=np.float32).reshape((2, 1, 1, 2))\n tf.compat.v1.nn.depthwise_conv2d(x, kernel, strides=[1, 1, 1, 1],\n padding='VALID').numpy()\n array([[[[10., 14.],\n [14., 20.]],\n [[18., 26.],\n [22., 32.]]]], dtype=float32)\n\n tf.compat.v1.nn.depthwise_conv2d(x, kernel, strides=[1, 1, 1, 1],\n padding=[[0, 0], [1, 0], [1, 0], [0, 0]]\n ).numpy()\n array([[[[ 0., 0.],\n [ 3., 4.],\n [ 6., 8.]],\n [[ 0., 0.],\n [10., 14.],\n [14., 20.]],\n [[ 0., 0.],\n [18., 26.],\n [22., 32.]]]], dtype=float32)\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input` | 4-D with shape according to `data_format`. |\n| `filter` | 4-D with shape `[filter_height, filter_width, in_channels, channel_multiplier]`. |\n| `strides` | 1-D of size 4. The stride of the sliding window for each dimension of `input`. |\n| `padding` | Controls how to pad the image before applying the convolution. Can be the string `\"SAME\"` or `\"VALID\"` indicating the type of padding algorithm to use, or a list indicating the explicit paddings at the start and end of each dimension. When explicit padding is used and data_format is `\"NHWC\"`, this should be in the form `[[0, 0], [pad_top, pad_bottom], [pad_left, pad_right], [0, 0]]`. When explicit padding used and data_format is `\"NCHW\"`, this should be in the form `[[0, 0], [0, 0], [pad_top, pad_bottom], [pad_left, pad_right]]`. |\n| `rate` | 1-D of size 2. The dilation rate in which we sample input values across the `height` and `width` dimensions in atrous convolution. If it is greater than 1, then all values of strides must be 1. |\n| `name` | A name for this operation (optional). |\n| `data_format` | The data format for input. Either \"NHWC\" (default) or \"NCHW\". |\n| `dilations` | Alias of rate. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A 4-D `Tensor` with shape according to `data_format`. E.g., for \"NHWC\" format, shape is `[batch, out_height, out_width, in_channels * channel_multiplier].` ||\n\n\u003cbr /\u003e"]]