tensorflow学习基础篇1——conv2d 函数说明
2017-03-11 15:35
183 查看
每次学习新知识总是走马观花,理解不深刻,从现在开始坚持将学习到的东西记录下来,一来方便以后回顾,二来加深理解
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tensorflow ——conv2d
tf.nn.conv2d(input, w, strides, padding)
其中 input 为输入,格式为[batch, height, width, channels], 分别为【输入的批次数量、图像的高(行数)、宽(列数)、通道(彩色为3,灰色为1)】
w 为卷积矩阵,二维、分别为[高,宽】
strides 为滑动窗口尺寸,分别为[1, height, width, 1], 通常 strides[0]=strdes[3]=1,因为一般不会在一个个图像,一个个通道之间滑动
padding 为扩展方式,有两种 vaild 和 same
1)不同的padding方式,VALID是采用丢弃的方式,比如上述的input_width=13,只允许滑动2次,多余的元素全部丢掉
2)SAME的方式,采用的是补全的方式,对于上述的情况,允许滑动3次,但是需要补3个元素,左奇右偶,在左边补一个0,右边补2个0
3) For the
the output height and width are computed as:
out_height = ceil(float(in_height) / float(strides[1]))
out_width = ceil(float(in_width) / float(strides[2]))
For the
the output height and width are computed as:
out_height = ceil(float(in_height - filter_height + 1) / float(strides[1]))
out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))
tensorflow 中源码如下所示,D:\python3.5\Lib\site-packages\tensorflow\python\ops\gen_nn_ops.py
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
tensorflow ——conv2d
tf.nn.conv2d(input, w, strides, padding)
其中 input 为输入,格式为[batch, height, width, channels], 分别为【输入的批次数量、图像的高(行数)、宽(列数)、通道(彩色为3,灰色为1)】
w 为卷积矩阵,二维、分别为[高,宽】
strides 为滑动窗口尺寸,分别为[1, height, width, 1], 通常 strides[0]=strdes[3]=1,因为一般不会在一个个图像,一个个通道之间滑动
padding 为扩展方式,有两种 vaild 和 same
1)不同的padding方式,VALID是采用丢弃的方式,比如上述的input_width=13,只允许滑动2次,多余的元素全部丢掉
2)SAME的方式,采用的是补全的方式,对于上述的情况,允许滑动3次,但是需要补3个元素,左奇右偶,在左边补一个0,右边补2个0
3) For the
SAMEpadding,
the output height and width are computed as:
out_height = ceil(float(in_height) / float(strides[1]))
out_width = ceil(float(in_width) / float(strides[2]))
For the
VALIDpadding,
the output height and width are computed as:
out_height = ceil(float(in_height - filter_height + 1) / float(strides[1]))
out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))
tensorflow 中源码如下所示,D:\python3.5\Lib\site-packages\tensorflow\python\ops\gen_nn_ops.py
def conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, data_format=None, name=None): r"""Computes a 2-D convolution given 4-D `input` and `filter` tensors. 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 the following: 1. Flattens the filter to a 2-D matrix with shape `[filter_height * filter_width * in_channels, output_channels]`. 2. Extracts image patches from the input tensor to form a *virtual* tensor of shape `[batch, out_height, out_width, filter_height * filter_width * in_channels]`. 3. 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] Must have `strides[0] = strides[ a1ba 3] = 1`. For the most common case of the same horizontal and vertices strides, `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, the format could be "NCHW", the data storage order of: [batch, in_channels, in_height, in_width]. name: A name for the operation (optional). Returns: A `Tensor`. Has the same type as `input`. """ result = _op_def_lib.apply_op("Conv2D", input=input, filter=filter, strides=strides, padding=padding, use_cudnn_on_gpu=use_cudnn_on_gpu, data_format=data_format, name=name) return result
参考网页:http://stackoverflow.com/questions/34642595/tensorflow-strides-argument
相关文章推荐
- TensorFlow学习---tf.nn.conv2d实现卷积操作
- TensorFlow基础笔记(11) conv2D函数
- TensorFlow深度学习入门——常用函数说明
- tensorflow学习:tf.nn.conv2d 和 tf.layers.conv2d
- ThinkPHP 学习笔记<一>:ThinkPHP常用函数说明
- python学习笔记三之函数(基础篇)
- 【OpenCV学习笔记】【函数学习】十(常用的OpenCV函数汇总说明)
- SVM学习笔记(2 )libsvm--svmtrain\svmpredict函数说明
- php中__get()和__set()函数学习笔记和实例说明!
- 深度学习 4. MatConvNet 相关函数解释说明,MatConvNet 细节理解,MatConvNet 代码理解
- php学习基础篇之基础函数(数学 日期 字符串)、php循环流程控制
- 韩顺平_轻松搞定网页设计(html+css+javascript)_第33讲_Object类_闭包_成员函数再说明_聪明的猪小练习_学习笔记_源代码图解_PPT文档整理
- 深度学习 6. MatConvNet 相关函数解释说明,MatConvNet 代码理解(二)cnn_mnist_init.m 的注释
- opencv学习(七)之图像卷积运算函数filter2D()
- tensorflow笔记 :常用函数说明
- 韩顺平 javascript教学视频_学习笔记16_Object类_闭包_成员函数再说明_聪明的猪小练习
- tensorflow笔记 :常用函数说明
- FireBreath学习之三 JSAPIAuto类的成员函数说明和插件调用DOM方法/属性一般形式
- Python学习笔记之常用函数及说明
- tensorflow学习之常用函数总结:tensorflow官方例子中的诸如tf.reduce_mean()这类函数