没有合适的资源?快使用搜索试试~ 我知道了~
对tensorflow中tf.nn.conv1d和layers.conv1d的区别详解
13 下载量 51 浏览量
2020-09-17
23:40:37
上传
评论
收藏 62KB PDF 举报
温馨提示
试读
3页
今天小编就为大家分享一篇对tensorflow中tf.nn.conv1d和layers.conv1d的区别详解,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
资源推荐
资源详情
资源评论
对对tensorflow中中tf.nn.conv1d和和layers.conv1d的区别详解的区别详解
今天小编就为大家分享一篇对tensorflow中tf.nn.conv1d和layers.conv1d的区别详解,具有很好的参考价值,希
望对大家有所帮助。一起跟随小编过来看看吧
在用tensorflow做一维的卷积神经网络的时候会遇到tf.nn.conv1d和layers.conv1d这两个函数,但是这两个函数有什么区别
呢,通过计算得到一些规律。
1.关于关于tf.nn.conv1d的解释,以下是的解释,以下是Tensor Flow中关于中关于tf.nn.conv1d的的API注解:注解:
Computes a 1-D convolution given 3-D input and filter tensors.
Given an input tensor of shape [batch, in_width, in_channels] if data_format is "NHWC", or [batch, in_channels,
in_width] if data_format is "NCHW", and a filter / kernel tensor of shape [filter_width, in_channels, out_channels],
this op reshapes the arguments to pass them to conv2d to perform the equivalent convolution operation.
Internally, this op reshapes the input tensors and invokes `tf.nn.conv2d`. For example, if `data_format` does not
start with "NC", a tensor of shape [batch, in_width, in_channels] is reshaped to [batch, 1, in_width, in_channels],
and the filter is reshaped to [1, filter_width, in_channels, out_channels]. The result is then reshaped back to
[batch, out_width, out_channels]
whereoutwidthisafunctionofthestrideandpaddingasinconv2dwhereoutwidthisafunctionofthestrideandpaddingasinconv2d
and returned to the caller.
Args: value: A 3D `Tensor`. Must be of type `float32` or `float64`. filters: A 3D `Tensor`. Must have the same type
as `input`. stride: An `integer`. The number of entries by which the filter is moved right at each step. padding:
'SAME' or 'VALID' use_cudnn_on_gpu: An optional `bool`. Defaults to `True`. data_format: An optional `string`
from `"NHWC", "NCHW"`. Defaults to `"NHWC"`, the data is stored in the order of [batch, in_width, in_channels].
The `"NCHW"` format stores data as [batch, in_channels, in_width]. name: A name for the operation (optional).
Returns:
A `Tensor`. Has the same type as input.
Raises:
ValueError: if `data_format` is invalid.
什么意思呢?就是说什么意思呢?就是说conv1d的参数含义:的参数含义:(以以NHWC格式为例,即,通道维在最后格式为例,即,通道维在最后)
1、value:在注释中,value的格式为:[batch, in_width, in_channels],batch为样本维,表示多少个样本,in_width为宽度
维,表示样本的宽度,in_channels维通道维,表示样本有多少个通道。 事实上,也可以把格式看作如下:[batch, 行数, 列数],
把每一个样本看作一个平铺开的二维数组。这样的话可以方便理解。
2、filters:在注释中,filters的格式为:[filter_width, in_channels, out_channels]。按照value的第二种看法,filter_width可以
看作每次与value进行卷积的行数,in_channels表示value一共有多少列(与value中的in_channels相对应)。out_channels表
示输出通道,可以理解为一共有多少个卷积核,即卷积核的数目。
3、stride:一个整数,表示步长,每次(向下)移动的距离(TensorFlow中解释是向右移动的距离,这里可以看作向下移动
的距离)。
4、padding:同conv2d,value是否需要在下方填补0。
5、name:名称。可省略。
首先从参数列表可以看出value指的输入的数据,stride就是卷积的步长,这里我们最有疑问的就是filters这个参数,那么我们
对filter进行简单的说明。从上面可以看到filters的格式为:[filter_width, in_channels, out_channels],这是一个数组的维度,对
应的是卷积核的大小,输入的channel的格式,和卷积核的个数,下面我们用例子说明问题:
import tensorflow as tf
import numpy as np
if __name__ == '__main__':
inputs = tf.constant(np.arange(1, 6, dtype=np.float32), shape=[1, 5, 1])
w = np.array([1, 2], dtype=np.float32).reshape([2, 1, 1])
# filter width, filter channels and out channels(number of kernels)
cov1 = tf.nn.conv1d(inputs, w, stride=1, padding='VALID')
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
out = sess.run(cov1)
print(out)
资源评论
weixin_38666753
- 粉丝: 7
- 资源: 909
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功