tf.compat.v1.nn.convolution
Вычисляет суммы N-мерных свёртки (на самом деле взаимной корреляции).
tf.compat.v1.nn.convolution(
input,
filter,
padding,
strides=None,
dilation_rate=None,
name=None,
data_format=None,
filters=None,
dilations=None
)
Это также поддерживает либо шаги вывода через необязательный strides параметр, либо атропную свёртку (также известную как свёртка с отверстиями или расширенная свёртка, на основе французского слова «trous», означающего отверстия на английском языке) через необязательный dilation_rate параметр. Однако в настоящее время шаги вывода не поддерживаются для атропных свёрток.
Конкретно, в случае, если data_format не начинается с "NC", при заданном ранге (N+2) input тензора формы
[количество_пачек, пространственная_форма_входа[0], ..., пространственная_форма_входа[N-1], количество_каналов_входа],
тензор ранга (N+2) filter тензора формы
[пространственная_форма_фильтра[0], ..., пространственная_форма_фильтра[N-1], количество_каналов_входа, количество_каналов_выхода],
необязательный dilation_rate тензор формы N (по умолчанию [1]*N) задающий скорость интерполяции/де интерполяции фильтра, и необязательный список из N strides (по умолчанию [1]*N), это вычисляет для каждой N-мерной пространственной позиции вывода (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]
где b — индекс в пакет, k — номер канала вывода, q — номер канала входных данных, и z — N-мерный пространственный сдвиг внутри фильтра. Здесь, padded_input получается путём заполнения нулями входных данных с использованием эффективной пространственной формы фильтра (spatial_filter_shape-1) * dilation_rate + 1 и шага вывода strides.
В случае, если data_format начинается с "NC", input и выход (но не filter) просто транспонируются следующим образом:
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))
Требуется, чтобы 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 здесь 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 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. |
© 2022 The TensorFlow Authors. All rights reserved.
Licensed under the Creative Commons Attribution License 4.0.
Code samples licensed under the Apache 2.0 License.
https://www.tensorflow.org/versions/r2.9/api_docs/python/tf/compat/v1/nn/convolution