Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TensorFlow · Class

layers.Conv1D

A Keras layer that performs one-dimensional convolution over spatial or temporal sequences. It transforms sliding input windows into a configurable number of output channels.

How it works

Conv1D slides a learned kernel across one spatial or temporal axis. It optionally adds a bias and activation, converting each input window into an output with the configured number of filters.

Syntax

tf.keras.layers.Conv1D(filters, kernel_size, strides=1, padding='valid', data_format=None, 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)

Parameters

NameTypeDescription
filtersintNumber of output filters and output channels.
kernel_sizeint or tuple/list of 1 integerWidth of the one-dimensional convolution window.
stridesint or tuple/list of 1 integerStep size of the convolution window.
paddingstringPadding mode: valid, same, or causal.
data_formatstring or NoneInput/output channel layout.
dilation_rateint or tuple/list of 1 integerDilation rate of the convolution.
groupsintNumber of input channels grouped together for convolution.
activationstring or callable or NoneOptional activation function.
use_biasboolWhether to add a bias vector.
kernel_initializerinitializerInitializer for the convolution kernel.
bias_initializerinitializerInitializer for the bias vector.
kernel_regularizerregularizer or NoneRegularizer for the kernel.

Returns

A 3D output tensor. With channels_last it has shape (batch_shape, new_steps, filters); with channels_first it has shape (batch_shape, filters, new_steps).

Key points

  • Conv1D is designed for one-dimensional spatial or temporal convolution.
  • A learned kernel moves across the input axis to generate output features.
  • The layer can add a trainable bias vector to its convolution results.
  • An optional activation function is applied after the convolution and bias addition.
  • Padding accepts valid, same, or causal, without case sensitivity.
  • The filters argument sets how many output feature channels the layer produces.

Common mistakes

  • Do not combine a stride greater than one with a dilation rate greater than one.
  • With valid padding, the temporal dimension can shrink because no border padding is added.
  • The default channels-last input must be rank three, with steps before channels.

Example: Apply a temporal convolution

import tensorflow as tf

layer = tf.keras.layers.Conv1D(
    filters=16, kernel_size=3, padding="same", activation="relu"
)
x = tf.random.normal((4, 10, 8))
y = layer(x)
print(y.shape)  # (4, 10, 16)

Creates a Conv1D layer, applies it to a batch of 10-step sequences with 8 channels, and prints the resulting shape.

When to use it

Extract local patterns across time steps.

Temporal sequence modeling

Learn features from ordered sensor or signal samples.

One-dimensional signal processing

Detect local patterns in embedded token sequences.

Text classification

Use sliding windows to model fixed-width recent history.

Time-series forecasting

Interview questions

QWhat does Conv1D compute and what shapes does it use?

Conv1D applies each learned filter across a single spatial or temporal dimension. For channels-last data, the input is shaped as batch, steps, channels, and the output is batch, new steps, filters.

Follow-up: How would you preserve the number of steps? Use padding="same" when the stride is one; the resulting output length matches the input length.

QWhat are filters and kernel_size responsible for?

filters determines the output-space size and therefore the number of channels in the result. kernel_size determines the width of the sliding convolution window.

Follow-up: What changes when data_format="channels_first"? The input and output place channels before the steps dimension.

QHow do bias, activation, and padding affect a Conv1D layer?

The layer can add a bias vector when use_bias is enabled and then apply activation when activation is not None. Its padding choices are valid, same, and causal.

Follow-up: When is causal padding useful? It prevents an output at a time step from depending on later input steps, making it suitable for some temporal models.

  • tf.keras.layers.Convolution1D
  • tf.keras.layers.DepthwiseConv1D
  • tf.keras.layers.SeparableConv1D
  • tf.keras.layers.Conv1DTranspose

Source: tf.keras.layers.Conv1D | TensorFlow v2.16.1. Checked 2026-10-15.