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
)
1D卷积层(例如,时间卷积)。
此层创建一个卷积核,该卷积核与层输入在单个空间(或时间)维度上进行卷积,以生成输出张量。如果 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 值不兼容。"valid"、"same" 或 "causal"(不区分大小写)之一。"valid" 表示不填充。"same" 结果是将零填充到输入上/下或左/右,使得输出具有与输入相同的宽度/高度维度。"causal" 结果是因果(扩张)卷积,例如,output[t] 不依赖于 input[t+1:]。在对应该模型不应违反时间顺序的时间数据进行建模时很有用。请参阅 WaveNet: A Generative Model for Raw Audio, section 2.1。channels_last(默认)或 channels_first 之一。输入中的维度顺序。channels_last 对应于形状为 (batch_size, width, channels) 的输入,而 channels_first 对应于形状为 (batch_size, channels, width) 的输入。请注意,channels_first 格式目前在 CPU 上的 TensorFlow 中不受支持。dilation_rate 值都与指定任何不等于 1 的 strides 值不兼容。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)。输入形状
3+D 张量,形状为:batch_shape + (steps, input_dim)
输出形状
3+D 张量,形状为:batch_shape + (new_steps, filters)。由于填充或步长,steps 值可能会发生变化。
返回
一个秩为 3 的张量,表示 activation(conv1d(inputs, kernel) + bias)。
引发
strides > 1 和 dilation_rate > 1 都存在时。