Conv1D
类tf_keras.layers.Conv1D(
filters,
kernel_size,
strides=1,
padding="valid",
data_format="channels_last",
dilation_rate=1,
groups=1,
activation=None,
use_bias=True,
kernel_initializer="glorot_uniform",
bias_initializer="zeros",
kernel_regularizer=None,
bias_regularizer=None,
activity_regularizer=None,
kernel_constraint=None,
bias_constraint=None,
**kwargs
)
一维卷积层(例如,时间卷积)。
此层创建一个卷积核,该卷积核在单个空间(或时间)维度上与层输入进行卷积,以生成输出张量。如果 use_bias
为 True,则创建一个偏差向量并将其添加到输出中。最后,如果 activation
不为 None
,则将其应用于输出。
在模型中将此层用作第一层时,请提供 input_shape
参数(整数或 None
的元组,例如,对于 10 个 128 维向量的序列,(10, 128)
,或对于 128 维向量的可变长度序列,(None, 128)
)。
示例
>>> # The inputs are 128-length vectors with 10 timesteps, and the
>>> # batch size is 4.
>>> input_shape = (4, 10, 128)
>>> x = tf.random.normal(input_shape)
>>> y = tf.keras.layers.Conv1D(
... 32, 3, activation='relu',input_shape=input_shape[1:])(x)
>>> print(y.shape)
(4, 8, 32)
>>> # With extended batch shape [4, 7] (e.g. weather data where batch
>>> # dimensions correspond to spatial location and the third dimension
>>> # corresponds to time.)
>>> input_shape = (4, 7, 10, 128)
>>> x = tf.random.normal(input_shape)
>>> y = tf.keras.layers.Conv1D(
... 32, 3, activation='relu', input_shape=input_shape[2:])(x)
>>> print(y.shape)
(4, 7, 8, 32)
参数
dilation_rate
值 != 1 不兼容。"valid"
、"same"
或 "causal"
之一(不区分大小写)。"valid"
表示不填充。"same"
会导致在输入的左右或上下均匀地填充零,以便输出具有与输入相同的宽度/高度维度。"causal"
会导致因果(扩张)卷积,例如 output[t]
不依赖于 input[t+1:]
。在对模型不应违反时间顺序的时间数据建模时很有用。请参阅 WaveNet:原始音频的生成模型,第 2.1 节。channels_last
(默认)或 channels_first
之一。输入中维度的顺序。channels_last
对应于形状为 (batch_size, width, channels)
的输入,而 channels_first
对应于形状为 (batch_size, channels, width)
的输入。请注意,TensorFlow 在 CPU 上目前不支持 channels_first
格式。dilation_rate
值 != 1 与指定任何 strides
值 != 1 不兼容。filters / groups
个滤波器进行卷积。输出是所有 groups
结果沿通道轴的连接。输入通道和 filters
都必须能够被 groups
整除。keras.activations
)。kernel
权重矩阵的初始化器(请参阅 keras.initializers
)。默认为 'glorot_uniform'。keras.initializers
)。默认为 'zeros'。kernel
权重矩阵的正则化函数(请参阅 keras.regularizers
)。keras.regularizers
)。keras.regularizers
)。keras.constraints
)。keras.constraints
)。输入形状
形状为 batch_shape + (steps, input_dim)
的 3+D 张量。
输出形状
形状为 batch_shape + (new_steps, filters)
的 3+D 张量。由于填充或步长,steps
值可能已更改。
返回值
一个表示 activation(conv1d(inputs, kernel) + bias)
的秩为 3 的张量。
引发异常
strides > 1
和 dilation_rate > 1
时。