tf.compat.v1.nn.convolution
Stay organized with collections
Save and categorize content based on your preferences.
Computes sums of N-D convolutions (actually cross-correlation).
tf.compat.v1.nn.convolution(
input,
filter,
padding,
strides=None,
dilation_rate=None,
name=None,
data_format=None,
filters=None,
dilations=None
)
This also supports either output striding via the optional strides
parameter
or atrous convolution (also known as convolution with holes or dilated
convolution, based on the French word "trous" meaning holes in English) via
the optional dilation_rate
parameter. Currently, however, output striding
is not supported for atrous convolutions.
Specifically, in the case that data_format
does not start with "NC", given
a rank (N+2) input
Tensor of shape
[num_batches,
input_spatial_shape[0],
...,
input_spatial_shape[N-1],
num_input_channels],
a rank (N+2) filter
Tensor of shape
[spatial_filter_shape[0],
...,
spatial_filter_shape[N-1],
num_input_channels,
num_output_channels],
an optional dilation_rate
tensor of shape N (defaults to [1]*N
) specifying
the filter upsampling/input downsampling rate, and an optional list of N
strides
(defaults to [1]*N
), this computes for each N-D spatial output
position (x[0], ..., x[N-1])
:
output[b, x[0], ..., x[N-1], k] =
sum_{z[0], ..., z[N-1], q}
filter[z[0], ..., z[N-1], q, k] *
padded_input[b,
x[0]*strides[0] + dilation_rate[0]*z[0],
...,
x[N-1]*strides[N-1] + dilation_rate[N-1]*z[N-1],
q]
where b is the index into the batch, k is the output channel number, q is the
input channel number, and z is the N-D spatial offset within the filter. Here,
padded_input
is obtained by zero padding the input using an effective
spatial filter shape of (spatial_filter_shape-1) * dilation_rate + 1
and
output striding strides
.
In the case that data_format
does start with "NC"
, the input
and output
(but not the filter
) are simply transposed as follows:
convolution(input, data_format, **kwargs) =
tf.transpose(convolution(tf.transpose(input, [0] + range(2,N+2) + [1]),
**kwargs),
[0, N+1] + range(1, N+1))
It is required that 1 <= N <= 3.
Args |
input
|
An (N+2)-D Tensor of type T , of shape
[batch_size] + input_spatial_shape + [in_channels] if data_format does
not start with "NC" (default), or
[batch_size, in_channels] + input_spatial_shape if data_format starts
with "NC".
|
filter
|
An (N+2)-D Tensor with the same type as input and shape
spatial_filter_shape + [in_channels, out_channels] .
|
padding
|
A string, either "VALID" or "SAME" . The padding algorithm.
"valid" means no padding. "same" results in padding evenly to
the left/right or up/down of the input such that output has the same
height/width dimension as the input when the strides are 1. See
here
for more information.
|
strides
|
Optional. Sequence of N ints >= 1. Specifies the output stride.
Defaults to [1]*N . If any value of strides is > 1, then all values of
dilation_rate must be 1.
|
dilation_rate
|
Optional. Sequence of N ints >= 1. Specifies the filter
upsampling/input downsampling rate. In the literature, the same parameter
is sometimes called input stride or dilation . The effective filter
size used for the convolution will be spatial_filter_shape +
(spatial_filter_shape - 1) * (rate - 1) , obtained by inserting
(dilation_rate[i]-1) zeros between consecutive elements of the original
filter in each spatial dimension i. If any value of dilation_rate is > 1,
then all values of strides must be 1.
|
name
|
Optional name for the returned tensor.
|
data_format
|
A string or None. Specifies whether the channel dimension of
the input and output is the last dimension (default, or if data_format
does not start with "NC"), or the second dimension (if data_format
starts with "NC"). For N=1, the valid values are "NWC" (default) and
"NCW". For N=2, the valid values are "NHWC" (default) and "NCHW".
For N=3, the valid values are "NDHWC" (default) and "NCDHW".
|
Returns |
A Tensor with the same type as input of shape
`[batch_size] + output_spatial_shape + [out_channels]`
if data_format is None or does not start with "NC", or
`[batch_size, out_channels] + output_spatial_shape`
if data_format starts with "NC",
where output_spatial_shape depends on the value of padding .
If padding == "SAME":
output_spatial_shape[i] = ceil(input_spatial_shape[i] / strides[i])
If padding == "VALID":
output_spatial_shape[i] =
ceil((input_spatial_shape[i] -
(spatial_filter_shape[i]-1) * dilation_rate[i])
/ strides[i]).
|
Raises |
ValueError
|
If input/output depth does not match filter shape, if padding
is other than "VALID" or "SAME" , or if data_format is invalid.
|
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.convolution\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/nn_ops.py#L1033-L1173) |\n\nComputes sums of N-D convolutions (actually cross-correlation). \n\n tf.compat.v1.nn.convolution(\n input,\n filter,\n padding,\n strides=None,\n dilation_rate=None,\n name=None,\n data_format=None,\n filters=None,\n dilations=None\n )\n\nThis also supports either output striding via the optional `strides` parameter\nor atrous convolution (also known as convolution with holes or dilated\nconvolution, based on the French word \"trous\" meaning holes in English) via\nthe optional `dilation_rate` parameter. Currently, however, output striding\nis not supported for atrous convolutions.\n\nSpecifically, in the case that `data_format` does not start with \"NC\", given\na rank (N+2) `input` Tensor of shape\n\n\\[num_batches,\ninput_spatial_shape\\[0\\],\n...,\ninput_spatial_shape\\[N-1\\],\nnum_input_channels\\],\n\na rank (N+2) `filter` Tensor of shape\n\n\\[spatial_filter_shape\\[0\\],\n...,\nspatial_filter_shape\\[N-1\\],\nnum_input_channels,\nnum_output_channels\\],\n\nan optional `dilation_rate` tensor of shape N (defaults to `[1]*N`) specifying\nthe filter upsampling/input downsampling rate, and an optional list of N\n`strides` (defaults to `[1]*N`), this computes for each N-D spatial output\nposition `(x[0], ..., x[N-1])`: \n\n output[b, x[0], ..., x[N-1], k] =\n sum_{z[0], ..., z[N-1], q}\n filter[z[0], ..., z[N-1], q, k] *\n padded_input[b,\n x[0]*strides[0] + dilation_rate[0]*z[0],\n ...,\n x[N-1]*strides[N-1] + dilation_rate[N-1]*z[N-1],\n q]\n\nwhere b is the index into the batch, k is the output channel number, q is the\ninput channel number, and z is the N-D spatial offset within the filter. Here,\n`padded_input` is obtained by zero padding the input using an effective\nspatial filter shape of `(spatial_filter_shape-1) * dilation_rate + 1` and\noutput striding `strides`.\n\nIn the case that `data_format` does start with `\"NC\"`, the `input` and output\n(but not the `filter`) are simply transposed as follows: \n\n convolution(input, data_format, **kwargs) =\n tf.transpose(convolution(tf.transpose(input, [0] + range(2,N+2) + [1]),\n **kwargs),\n [0, N+1] + range(1, N+1))\n\nIt is required that 1 \\\u003c= N \\\u003c= 3.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `input` | An (N+2)-D `Tensor` of type `T`, of shape `[batch_size] + input_spatial_shape + [in_channels]` if data_format does not start with \"NC\" (default), or `[batch_size, in_channels] + input_spatial_shape` if data_format starts with \"NC\". |\n| `filter` | An (N+2)-D `Tensor` with the same type as `input` and shape `spatial_filter_shape + [in_channels, out_channels]`. |\n| `padding` | A string, either `\"VALID\"` or `\"SAME\"`. The padding algorithm. `\"valid\"` means no padding. `\"same\"` results in padding evenly to the left/right or up/down of the input such that output has the same height/width dimension as the input when the strides are 1. See [here](https://www.tensorflow.org/api_docs/python/tf/nn#notes_on_padding_2) for more information. |\n| `strides` | Optional. Sequence of N ints \\\u003e= 1. Specifies the output stride. Defaults to `[1]*N`. If any value of strides is \\\u003e 1, then all values of dilation_rate must be 1. |\n| `dilation_rate` | Optional. Sequence of N ints \\\u003e= 1. Specifies the filter upsampling/input downsampling rate. In the literature, the same parameter is sometimes called `input stride` or `dilation`. The effective filter size used for the convolution will be `spatial_filter_shape + (spatial_filter_shape - 1) * (rate - 1)`, obtained by inserting (dilation_rate\\[i\\]-1) zeros between consecutive elements of the original filter in each spatial dimension i. If any value of dilation_rate is \\\u003e 1, then all values of strides must be 1. |\n| `name` | Optional name for the returned tensor. |\n| `data_format` | A string or None. Specifies whether the channel dimension of the `input` and output is the last dimension (default, or if `data_format` does not start with \"NC\"), or the second dimension (if `data_format` starts with \"NC\"). For N=1, the valid values are \"NWC\" (default) and \"NCW\". For N=2, the valid values are \"NHWC\" (default) and \"NCHW\". For N=3, the valid values are \"NDHWC\" (default) and \"NCDHW\". |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `Tensor` with the same type as `input` of shape \u003cbr /\u003e `[batch_size] + output_spatial_shape + [out_channels]` if data_format is None or does not start with \"NC\", or `[batch_size, out_channels] + output_spatial_shape` if data_format starts with \"NC\", where `output_spatial_shape` depends on the value of `padding`. If padding == \"SAME\": output_spatial_shape\\[i\\] = ceil(input_spatial_shape\\[i\\] / strides\\[i\\]) If padding == \"VALID\": output_spatial_shape\\[i\\] = ceil((input_spatial_shape\\[i\\] - (spatial_filter_shape\\[i\\]-1) \\* dilation_rate\\[i\\]) / strides\\[i\\]). ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|------------------------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | If input/output depth does not match `filter` shape, if padding is other than `\"VALID\"` or `\"SAME\"`, or if data_format is invalid. |\n\n\u003cbr /\u003e"]]