How to adapt ResNet to time series data
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
ResNet is an image architecture, but the core idea is broader than computer vision. A residual block lets a model learn a refinement to its input instead of relearning the entire transformation, and that idea works well for temporal signals too. For time series, the main adaptation is replacing image-style spatial operations with sequence-aware ones.
Translate image blocks into sequence blocks
In an image ResNet, a convolution slides across height and width. In a time-series ResNet, a Conv1D slides across the time axis instead. In Keras, the usual input shape is (timesteps, channels), where channels means features per time step.
That mapping is straightforward:
- univariate series: one channel
- multivariate series: one channel per measured feature
- image
Conv2D: replaced byConv1D - image global average pooling: replaced by temporal global average pooling
Residual connections still matter for the same reason they matter in vision: deeper stacks are easier to optimize when each block can preserve the input path.
Build a 1D residual block
The usual pattern is two or three Conv1D layers, normalization, a nonlinearity, and a skip path. If the number of filters changes, project the skip path with a 1x1 convolution so the shapes match.
This model is suitable for sequence classification. The first dimension is time, and the second is the number of input variables.
Match the head to the problem
The residual trunk is only part of the design. The output head should reflect the task:
- classification: global pooling followed by a dense classifier
- regression: global pooling followed by one or more linear outputs
- forecasting: a dense layer that predicts the next value, or a sequence head that predicts multiple future steps
For many forecasting problems, you train on sliding windows. Each training example is a recent chunk of history, and the label is the next point or next horizon.
That example shows the mechanical change from image classification to next-step forecasting. The residual idea stays the same, but the input windowing and output layer change.
Decide how much temporal context to capture
Time series often need longer context than small image patches. You can increase receptive field by stacking more blocks, using larger kernels, or using dilated convolutions. Residual connections help here because deeper temporal models are otherwise harder to train.
You should also think about whether your problem is local or global:
- local patterns: short kernels often work well
- seasonal or long-range patterns: deeper stacks or dilation help
- irregular timestamps: resampling or feature engineering may matter more than architecture choice
In practice, a 1D ResNet is often a strong baseline before trying transformers or more elaborate hybrids.
Common Pitfalls
One common mistake is getting the input shape backwards. In Keras, the typical order is (timesteps, channels), not (channels, timesteps).
Another mistake is copying an image ResNet too literally. Aggressive downsampling can destroy short-lived spikes or boundary events that matter in time series.
Teams also over-focus on architecture and under-focus on data preparation. Normalization, window construction, label alignment, and handling missing timestamps usually affect results more than adding extra residual blocks.
Finally, do not assume classification tricks transfer directly to forecasting. A classifier head and a forecast head answer different questions even if the trunk looks similar.
Summary
- ResNet adapts to time series by replacing
Conv2Dblocks withConv1Dresidual blocks. - The usual input layout is
(timesteps, channels). - Use projection shortcuts when filter counts or stride change.
- Choose the output head based on classification, regression, or forecasting.
- Good windowing, normalization, and label alignment are as important as model depth.
Related reading
- How to add additional classes to a pre-trained object detection model and train it to detect all of the classes pre-trained new?
- How to add and remove new layers in keras after loading weights?
- How to add attention layer to a Bi-LSTM
- How to add attention layer to a Bi-LSTM
- How to add Dropout in Keras functional model?
- How to add regularizations in TensorFlow?
- how to add text preprocessing tokenization step into Tensorflow model
- How to apply data augmentation in TensorFlow 2.0 after tfds.load
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.