在用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。
新聞熱點
疑難解答