Deep Declarative Dynamic Time Warping for End-to-End Learning of Alignment Paths

Ming Xu, Sourav Garg, Michael Milford, Stephen Gould

TL;DR

Researchers have developed DecDTW, a new differentiable layer for neural networks that allows models to learn directly from optimal temporal alignment paths. By formulating Dynamic Time Warping (DTW) as a continuous optimization problem and using implicit differentiation, DecDTW enables end-to-end training for tasks where the exact alignment between sequences—not just a "soft" approximation—is the primary goal.

What Problem Does This Paper Address?

Dynamic Time Warping (DTW) is a classic algorithm used to find the best alignment between two sequences that might vary in speed (e.g., matching a singer's performance to a musical score). However, standard DTW is discrete and non-differentiable, making it difficult to plug into modern deep learning pipelines.

Existing solutions like Soft-DTW use a "soft-min" operator to make the algorithm differentiable. While this works for calculating distances, it produces a "blurry" or "soft" expected alignment path. In many real-world applications—like robotics navigation or music transcription—we care about the exact alignment path. If your loss function depends on how accurately you've predicted a specific timestamp match, a blurry approximation isn't good enough. The authors aim to bridge this gap by making the optimal path itself differentiable.

Methods

The authors introduce DecDTW, which treats the DTW problem as a Deep Declarative Network (DDN). Instead of differentiating through the steps of an algorithm, they define the output as the solution to an optimization problem.

DecDTW Architecture Pipeline
  1. Continuous Formulation (GDTW): They move away from discrete indices and define a continuous warp function $\phi(t)$ that maps time from one signal to another.
  2. Constrained Optimization: The problem is framed as minimizing a signal loss (how well the features match) plus a regularization term (to keep the warp "smooth" and close to a 1:1 speed), subject to local constraints (non-decreasing time) and global constraints (boundary conditions).
Comparison of Classic DTW and Continuous GDTW
  1. Forward Pass: They solve this optimization using a custom iterative dynamic programming approach that refines the path to find a high-precision global optimum.
  2. Backward Pass: Using the implicit function theorem, they compute gradients of the optimal path with respect to the input features and even the constraints themselves. This allows the network to learn better feature representations specifically tuned to produce accurate alignments.

Datasets

The paper evaluates DecDTW on two distinct, challenging domains:

  • Audio-to-Score Alignment: Using 193 piano performances from the MAESTRO and Kernscores datasets. The goal is to align raw audio to MIDI scores.
  • Visual Place Recognition (VPR): Using the Oxford RobotCar dataset. This involves aligning a sequence of images from a moving vehicle to a previously recorded database sequence to determine the robot's exact location, even under different weather conditions (Sunny, Snow, Overcast).

Key Insights and Ideas

  • Sharpness Matters: Unlike Soft-DTW, which averages over many possible paths, DecDTW identifies the single best path. This "sharpness" is crucial when the ground truth is a specific sequence of events.
  • Learnable Constraints: Because the constraints (like the maximum allowed "warp" speed) are part of the optimization problem, DecDTW can actually learn the best constraints for a specific task during training.
  • Implicit vs. Algorithmic Differentiation: By using implicit differentiation, the memory cost of the backward pass doesn't explode with sequence length, unlike "unrolling" a traditional algorithm.
  • GDTW vs. DTW: The continuous-time variant (GDTW) allows for sub-frame alignment, which the authors found leads to more accurate results in real-world tasks compared to discrete matching.

Key Results

  • Audio Alignment: DecDTW achieved state-of-the-art results. For "melspec" features, it reduced the Temporal Average Error (TimeErr) from 56ms (baseline) to 16ms, even outperforming highly engineered specialized features.
  • Robotics (VPR): In the Oxford RobotCar tests, DecDTW significantly improved localization accuracy. At a strict 2-meter error threshold in overcast conditions, DecDTW achieved 25.4% accuracy, compared to just 0.7% for the DILATE baseline (a state-of-the-art soft-path method).
  • Feature Learning: The results show that DecDTW is exceptionally good at "teaching" a feature extractor (like a GRU or VGG backbone) what details to focus on to make sequences easier to align.

Limitations and Future Work

  • Computational Overhead: DecDTW is significantly slower than standard discrete DTW (roughly 15-50x slower at inference) due to the iterative refinement needed for the continuous optimization.
  • Complexity: The implementation is more complex than standard "soft" relaxations, requiring a custom solver to ensure the forward pass is accurate enough for stable gradients.
  • Future Directions: The authors suggest exploring more compact parameterizations of the warp function to improve speed and integrating more complex DTW variants (like those that handle jumps or repeats in the data) into the declarative framework.

Summary updated

BibTeX
@inproceedings{xu2023deep,
  author = {Ming Xu and Sourav Garg and Michael Milford and Stephen Gould},
  title = {{Deep Declarative Dynamic Time Warping for End-to-End Learning of Alignment Paths}},
  booktitle = {International Conference on Learning Representations},
  year = {2023},
  url = {https://openreview.net/forum?id=UClBPxIZqnY},
}
Figure