tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, data_format=None, name=None)
Computes a 2-D convolution given 4-D input and filter tensors.
通过输入规定的四维input和filter计算二维卷积.
GIven an input tensor of shape [batch, in_height, in_width, in_channels] and a filter / kernel tensor of shape [filter_height, filter_width, in_channels, out_channels], this op performs thr following:
给定一个input的张量[batch, in_height, in_width, in_channels]和一个过滤器 / 内核 张量 [filter_height, filter_width, in_channels, out_channels]后,执行以下操作:
Flattens the filter to a 2-D matrix with shape [filter_height * filter_width * in_channels, output_channels].
Extracts image patches from the input tensor to from a virtual tensor of shape [batch, out_height, out_width, filter_height * filter_width * in_channels].
For each patch, right-multiplies the filter matrix and the image patch vector.
In detail, with the default NHWC format.
output[b, i, j, k] = sum_{di, dj, q} input[b, strides[1] * i + di, strides[2] * j + dj, q] * filter[di, dj, q, k]展平filter为一个形状为[filter_height * filter_width * in_channels, output_channels]的二维矩阵。
从input提取图片集形成一个大小为[batch, out_height, out_width, filter_height * filter_width * in_channels]的虚拟张量。
循环每个图片集,对filter矩阵右乘图片集矢量。
在默认的NHWC格式下,详细的过程是
output[b, i, j, k] = sum_{di, dj, q} input[b, strides[1] * i + di, strides[2] * j + dj, q] * filter[di, dj, q, k]
Must have strides[0] = strides[3] = 1. For the most common case of the same horizontal and vertices strides, strides = [1, stride, stride, 1].
strides的参数里面必须存在strides[0] = strides[3] = 1这种关系. 在大多数情况下垂直和水平的步幅是一样的,即strides = [1, stride, stride, 1].
Args:
- input : A tensor. Must be one of the following types: half, float32, float64.
- filter : A tensor. Must have the same type as input.
- strides : A list of ints. 1-D of length 4. The stride of the sliding window for each dimension of input. Must be in the same order as the dimension specified with format.
- padding : A string from : "SAME", "VALID". The type of padding algorithm to use.
- use_cudnn_on_gpu : An optional bool. Defaults to True.
-
data_format : An optional string from : "NHWC", "NCHW".Defaults to "NHWC".
Specify the data format of the input and output data. WIth the default format "NHWC", the data is stored in the order of : [batch, in_height, in_width, in_channels]. ALternatively, thr format could be "NCHW", the data storage order of: [batch, in_channels, in_height, in_width]. - name : A name for the operation(optional)
参数:
- input : 一个张量. 必须为下列类型之一: half, float32, float64.
- filter : 一个张量. 必须要跟input的类型一致.
- strides : 一个整数列表. 长度为4的一维矩阵. input的每一个维度的滑动窗格的步幅. 必须与使用data_format指定的维度具有相同的顺序.
- padding : 字符串类型,可选值有 : "SAME", "VALID". 选择使用的填充算法的类型.
-
use_cudnn_on_gpu : 一个可选的布尔参数. 默认为
True
-
data_format : 一个可选的字符串参数,可选值有 : "NHWC", "NCHW".默认是"NHWC".
为input和output指明数据类型. 使用默认格式"NHWC"时, 数据会被存储为: [batch, in_height, in_width, in_channels]. 或者,当格式为"NCHW"时, 数据会被存储为: [batch, in_channels, in_height, in_width]. - name : 操作的名称(可选)
Returns:
A Tensor. Has the same type as input.
返回值:
一个张量, 跟input类型相同