Paper Notes: RAFT: Recurrent All-Pairs Field Transforms for Optical Flow

This paper introduces an optical flow network called Recurrent All-Pairs Field Transforms (RAFT) that achieves state-of-the-art (SOTA) results on benchmark datasets. The main highlights are:

(1) State-of-the-art accuracy: On KITTI, RAFT reduces error by 16% compared with the previous best result, bringing it down to 5.10% (F1). On Sintel, it reduces pixel error by 30%. These are the best results to date.
(2) Strong generalization: When trained only on synthetic datasets, RAFT reduces error by 40% compared with the best-performing network also trained only on synthetic data.
(3) High efficiency: RAFT runs at 10 FPS on 1088×436 videos using a 1080Ti GPU. It also requires ten times fewer training iterations.

1 Approach

Figure 1

The RAFT network consists of three components:

(1) Feature Encoder: Extracts a feature vector for each pixel.
(2) Correlation Layer: Computes a matrix of inner products for all pairs of features, with dimensions W \times H \times W \times H.
(3) Update Operator: Uses a GRU recurrent neural network to iteratively refine the optical flow.

Figure 2

1.1 Feature Extraction

Features are extracted from both images, I_1 and I_2, by a network called the Feature Encoder. The left half of the figure above shows the Feature Extraction component. It outputs a feature map at 1/8 of the input resolution: g_{\theta}: \mathbb{R}^{H \times W \times 3} \mapsto \mathbb{R}^{H / 8 \times W / 8 \times D}, where D=256. The authors also introduce a Context Encoder, whose output is denoted by h_{\theta}. It has the same architecture as the Feature Encoder but is applied only to I_1.

1.2  Computing Visual Similarity

Given the feature maps g_{\theta}\left(I_{1}\right) \in \mathbb{R}^{H \times W \times D} and g_{\theta}\left(I_{2}\right) \in \mathbb{R}^{H \times W \times D}, this step computes the dot product for every pair of features across the two images:

\mathbf{C}\left(g_{\theta}\left(I_{1}\right), g_{\theta}\left(I_{2}\right)\right) \in \mathbb{R}^{H \times W \times H \times W}, \quad C_{i j k l}=\sum_{h} g_{\theta}\left(I_{1}\right)_{i j h} \cdot g_{\theta}\left(I_{2}\right)_{k l h}\tag{1}

Correlation Pyramid

The paper builds a four-level correlation pyramid corresponding to the four levels of extracted features: \left\{\mathbf{C}^{1}, \mathbf{C}^{2}, \mathbf{C}^{3}, \mathbf{C}^{4}\right\}. The last two levels are downsampled using pooling. The process is illustrated below:

Figure 3

Correlation Lookup

Given an optical flow field (\mathbf{f}_1, \mathbf{f}_2), a pixel x=(u, v) in I_1 corresponds to the location \mathbf{x}^{\prime}=\left(u+f^{1}(u), v+f^{2}(v)\right) in I_2. We define a local neighborhood:

\mathcal{N}\left(\mathbf{x}^{\prime}\right)_{r}=\left\{\mathbf{x}^{\prime}+\mathbf{d} \mathbf{x} \mid \mathbf{d} \mathbf{x} \in \mathbb{Z}^{2},\|\mathbf{d} \mathbf{x}\|_{1} \leq r\right\}\tag{2}

When looking up correlations at each level of the pyramid, we index the kth level \mathbf{C}_{k} using \mathcal{N}\left(\mathbf{x}^{\prime} / 2^{k}\right)_{r}. This means that a neighborhood at a coarser level covers a larger receptive field. For example, at level k=4, using r=4 corresponds to 256 pixels at the original resolution. Finally, the features from all levels are stacked into a single layer.

Efficient Computation for High Resolution Images

\mathbf{C}_{i j k l}^{m}=\frac{1}{2^{2 m}} \sum_{p}^{2^{m}} \sum_{q}^{2^{m}}\left\langle g_{i, j}^{(1)}, g_{2^{m} k+p, 2^{m} l+q}^{(2)}\right\rangle=\left\langle g_{i, j}^{(1)}, \frac{1}{2^{2 m}}\left(\sum_{p}^{2^{m}} \sum_{q}^{2^{m}} g_{2^{m} k+p, 2^{m} l+q}^{(2)}\right)\right\rangle\tag{3}

1.3 Iterative Updates

Starting from an initial optical flow estimate of \mathbf{f}_0=0, the iterative update layer refines a sequence of optical flow estimates \left\{\mathbf{f}_{1}, \ldots, \mathbf{f}_{N}\right\} over k iterations. The update layer takes the flow, correlation, context, and previous hidden state as inputs and outputs the gradient \Delta \mathbf{f} for the current iteration. The optical flow is then updated as follows:

\mathbf{f}_{k+1} = \Delta \mathbf{f} + \mathbf{f}_{k+1}\tag{4}

Training this recurrent network drives the optical flow estimates to converge: \mathbf{f}_k → \mathbf{f}_∗.

Initialization

By default, the optical flow field is initialized to zero. In video mode, the previous result can be used as a warm start.

Inputs

As shown in Figure 2, the current optical flow \mathbf{f}_k passes through two convolutional layers and is then combined with the Correlation features, which pass through one convolutional layer. The result is combined directly with the Context features to form the input to the GRU.

Update

The update layer is built around a GRU unit in which fully connected layers are replaced by convolutions. This GRU is called a ConvGRU and is defined as follows:

\begin{array}{l}z_{t}=\sigma\left(\operatorname{Conv}_{3 \times 3}\left(\left[h_{t-1}, x_{t}\right], W_{z}\right)\right) \\r_{t}=\sigma\left(\operatorname{Conv}_{3 \times 3}\left(\left[h_{t-1}, x_{t}\right], W_{r}\right)\right) \\ \tilde{h}_{t}=\tanh \left(\operatorname{Conv}_{3 \times 3}\left(\left[r_{t} \odot h_{t-1}, x_{t}\right], W_{h}\right)\right) \\ h_{t}=\left(1-z_{t}\right) \odot h_{t-1}+z_{t} \odot \tilde{h}_{t}\end{array}\tag{5}

Here, x_t denotes the input defined above.

Flow Prediction

The GRU output passes through two convolutions to produce the optical flow prediction. This prediction is at 1/8 of the original resolution. During inference, it is restored to the original resolution by the Upsampling operation described below.

Upsampling

Because the predicted flow is at 1/8 of the original resolution, the Upsampling component reconstructs the full-resolution flow by interpolating predictions from a 3×3 neighborhood on the coarse grid. Two convolutions followed by a softmax produce a mask of size H/8×W/8×(8×8×9). The full-resolution optical flow is then obtained by weighting the coarse predictions with this mask. The network outputs a tensor of size H \times W \times 2, where the two channels represent the x and y offsets. This layer can be implemented using PyTorch’s unfold operation.

1.4 Supervision

We define the loss as follows:

\mathcal{L}=\sum_{i=1}^{N} \gamma^{N-i}\left\|\mathbf{f}_{g t}-\mathbf{f}_{i}\right\|_{1}\tag{6}

We compute the l_1 distance between each optical flow prediction in the sequence and the ground truth f_{gt}, assigning a different weight to each stage. In this paper, \gamma = 0.8.

2 Experiments

The authors ran experiments on the Sintel and KITTI datasets. The results are shown below:

Sintel

KITTI

The data are shown below

The results show a clear improvement over several of the latest networks. See the original paper for details.

Personal Takeaways

This paper was presented as an oral at ECCV 2020. It swept the existing optical flow leaderboards, arguably setting a new standard, and is well worth studying. My impression is that the GRU Update module plays a major role and goes a long way toward improving transferability. It also performs well in practice. That said, the network as a whole is computationally demanding and fairly difficult to compress.

Download the Paper

Add a Comment

Your email address will not be published. Required fields are marked *