在用tensorflow做一維的卷積神經(jīng)網(wǎng)絡(luò)的時(shí)候會(huì)遇到tf.nn.conv1d和layers.conv1d這兩個(gè)函數(shù),但是這兩個(gè)函數(shù)有什么區(qū)別呢,通過計(jì)算得到一些規(guī)律。
1.關(guān)于tf.nn.conv1d的解釋,以下是Tensor Flow中關(guān)于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的參數(shù)含義:(以NHWC格式為例,即,通道維在最后)
1、value:在注釋中,value的格式為:[batch, in_width, in_channels],batch為樣本維,表示多少個(gè)樣本,in_width為寬度維,表示樣本的寬度,in_channels維通道維,表示樣本有多少個(gè)通道。 事實(shí)上,也可以把格式看作如下:[batch, 行數(shù), 列數(shù)],把每一個(gè)樣本看作一個(gè)平鋪開的二維數(shù)組。這樣的話可以方便理解。
2、filters:在注釋中,filters的格式為:[filter_width, in_channels, out_channels]。按照value的第二種看法,filter_width可以看作每次與value進(jìn)行卷積的行數(shù),in_channels表示value一共有多少列(與value中的in_channels相對(duì)應(yīng))。out_channels表示輸出通道,可以理解為一共有多少個(gè)卷積核,即卷積核的數(shù)目。
3、stride:一個(gè)整數(shù),表示步長(zhǎng),每次(向下)移動(dòng)的距離(TensorFlow中解釋是向右移動(dòng)的距離,這里可以看作向下移動(dòng)的距離)。
4、padding:同conv2d,value是否需要在下方填補(bǔ)0。
新聞熱點(diǎn)
疑難解答
圖片精選