Paper Notes: End-to-End Learnable Geometric Vision by Backpropagating PnP Optimization

This paper explores how to combine the traditional PnP method with deep learning. The idea is fairly straightforward: backpropagate the residuals from the traditional PnP solver to the neural network to enable end-to-end training, and solve PnP without known data associations (Blind PnP).

1 Backpropagating a PnP solver (BPnP)

First, let’s formulate the PnP problem mathematically.

Let g be a PnP solver whose output y is the estimated 6DoF pose:

\boldsymbol{y}=g(\boldsymbol{x}, \boldsymbol{z}, \mathbf{K})\tag{1}

Here, x contains the observed 2D coordinates of feature points in the image, z contains the coordinates of the corresponding 3D points in space, and K contains the camera intrinsics. The 2D and 3D points are paired one-to-one:

\begin{array}{l}\boldsymbol{x}=\left[\begin{array}{llll}\boldsymbol{x}_{1}^{T} & \boldsymbol{x}_{2}^{T} & \ldots & \boldsymbol{x}_{n}^{T}\end{array}\right]^{T} \in \mathbb{R}^{2 n \times 1} \\\boldsymbol{z}=\left[\begin{array}{llll}\boldsymbol{z}_{1}^{T} & \boldsymbol{z}_{2}^{T} & \ldots & \boldsymbol{z}_{n}^{T}\end{array}\right]^{T} \in \mathbb{R}^{3 n \times 1}\end{array}\tag{2}
Solving PnP amounts to solving the following optimization problem:

\boldsymbol{y}=\underset{\boldsymbol{y} \in S E(3)}{\arg \min } \sum_{i=1}^{n}\left\|\boldsymbol{r}_{i}\right\|_{2}^{2}\tag{3}
Here, \boldsymbol{\pi}_{i}=\pi\left(\boldsymbol{z}_{i} \mid \boldsymbol{y}, \mathbf{K}\right) is the projection, and \boldsymbol{r}_{i}=\boldsymbol{x}_{i}-\boldsymbol{\pi}_{i} is the reprojection error.

This can be written more compactly as:

\boldsymbol{y}=\underset{\boldsymbol{y} \in S E(3)}{\arg \min } \quad\|\boldsymbol{x}-\boldsymbol{\pi}\|_{2}^{2}\tag{4}
where:

\boldsymbol{\pi}:=\left[\boldsymbol{\pi}_{1}^{T}, \ldots, \boldsymbol{\pi}_{n}^{T}\right]^{T}\tag{5}

1.1 Implicit differentiation

1.2 Constructing the constraint function f

Define the PnP objective function as:

o(\boldsymbol{x}, \boldsymbol{y}, \boldsymbol{z}, \mathbf{K})=\sum_{i=1}^{n}\left\|\boldsymbol{r}_{i}\right\|_{2}^{2}\tag{6}
At a minimum of the objective function, we have:

\left.\frac{\partial o(\boldsymbol{x}, \boldsymbol{y}, \boldsymbol{z}, \mathbf{K})}{\partial \boldsymbol{y}}\right|_{\boldsymbol{y}=g(\boldsymbol{x}, \boldsymbol{z}, \mathbf{K})}=\mathbf{0}\tag{7}
We then define:

f(\boldsymbol{x}, \boldsymbol{y}, \boldsymbol{z}, \mathbf{K})=\left[f_{1}, \ldots, f_{m}\right]^{T}\tag{8}
where:

\begin{aligned}f_{j} &=\frac{\partial o(\boldsymbol{x}, \boldsymbol{y}, \boldsymbol{z}, \mathbf{K})}{\partial y_{j}} \\&=2 \sum_{i=1}^{n}\left\langle\boldsymbol{r}_{i}, \frac{\partial \boldsymbol{r}_{i}}{\partial y_{j}}\right\rangle \\&=\sum_{i=1}^{n}\left\langle\boldsymbol{r}_{i}, \boldsymbol{c}_{i j}\right\rangle \\\boldsymbol{c}_{i j} &=-2 \frac{\partial \boldsymbol{\pi}_{i}}{\partial y_{j}}\end{aligned}\tag{9}

1.3 Forward and backward pass

First, we rewrite the PnP solver to include an initial pose y^{(0)} :

\boldsymbol{y}=g\left(\boldsymbol{x}, \boldsymbol{z}, \mathbf{K}, \boldsymbol{y}^{(0)}\right)\tag{10}
By implicit differentiation, we get:

\begin{aligned}\frac{\partial g}{\partial \boldsymbol{x}} &=-\left[\frac{\partial f}{\partial \boldsymbol{y}}\right]^{-1}\left[\frac{\partial f}{\partial \boldsymbol{x}}\right] \\\frac{\partial g}{\partial \boldsymbol{z}} &=-\left[\frac{\partial f}{\partial \boldsymbol{y}}\right]^{-1}\left[\frac{\partial f}{\partial \boldsymbol{z}}\right] \\\frac{\partial g}{\partial \mathbf{K}} &=-\left[\frac{\partial f}{\partial \boldsymbol{y}}\right]^{-1}\left[\frac{\partial f}{\partial \mathbf{K}}\right]\end{aligned}\tag{11}
Given the output gradient \nabla \boldsymbol{y} during backpropagation through the neural network, we can compute the gradient for each input as follows:

\begin{aligned}\nabla \boldsymbol{x} &=\left[\frac{\partial g}{\partial \boldsymbol{x}}\right]^{T} \nabla \boldsymbol{y} \\\nabla \boldsymbol{z} &=\left[\frac{\partial g}{\partial \boldsymbol{z}}\right]^{T} \nabla \boldsymbol{y} \\\nabla \mathbf{K} & =\left[\frac{\partial g}{\partial \mathbf{K}}\right]^{T} \nabla \boldsymbol{y}\end{aligned}\tag{12}

1.4 Implementation notes

2 End-to-end learning with BPnP

2.1 Pose estimation

This section describes how to estimate the pose y from the observed keypoint coordinates x, given a known map z and camera intrinsics K. The workflow is as follows:

The loss is defined as:

l(\boldsymbol{x}, \boldsymbol{y})=\left\|\pi(\boldsymbol{z} \mid \boldsymbol{y}, \mathbf{K})-\pi\left(\boldsymbol{z} \mid \boldsymbol{y}^{*}, \mathbf{K}\right)\right\|_{2}^{2}+\lambda R(\boldsymbol{x}, \boldsymbol{y})\tag{13}

A key gradient used in the update step is computed as follows:

\frac{\partial \ell}{\partial \boldsymbol{\theta}}=\frac{\partial l}{\partial \boldsymbol{y}} \frac{\partial g}{\partial \boldsymbol{x}} \frac{\partial h}{\partial \boldsymbol{\theta}}+\frac{\partial l}{\partial \boldsymbol{x}} \frac{\partial h}{\partial \boldsymbol{\theta}}\tag{14}

The figures below show how the two setups converge. In both figures, the first row uses \lambda = 1 and the second row uses \lambda = 0.

Figure 1 shows the case where h(I; \theta) = \theta.

Figure 2 shows the results for a modified VGG11 network.

Both experiments converge with or without the regularization term, but both achieve better convergence when \lambda = 1.

2.2 SfM with calibrated cameras

This section is about

The loss is defined as follows:

l\left(\left\{\boldsymbol{y}^{(j)}\right\}_{j=1}^{N}, \boldsymbol{z}\right)=\sum_{j=1}^{N}\left\|\boldsymbol{x}^{(j)}-\pi\left(\boldsymbol{z}^{(j)} \mid \boldsymbol{y}^{(j)}, \mathbf{K}\right)\right\|_{2}^{2}\tag{15}
The gradient for this workflow is derived as follows:

\frac{\partial \ell}{\partial \boldsymbol{\theta}}=\sum_{j=1}^{N}\left(\frac{\partial l}{\partial \boldsymbol{z}^{(j)}} \frac{\partial \boldsymbol{z}^{(j)}}{\partial \boldsymbol{\theta}}+\frac{\partial l}{\partial \boldsymbol{y}^{(j)}} \frac{\partial \boldsymbol{y}^{(j)}}{\partial \boldsymbol{z}^{(j)}} \frac{\partial \boldsymbol{z}^{(j)}}{\partial \boldsymbol{\theta}}\right)\tag{16}
The figure below shows an example of SfM convergence:

2.3 Camera calibration

The camera calibration workflow is as follows:

The loss is defined as follows:

l(\mathbf{K}, \boldsymbol{y})=\|\boldsymbol{x}-\pi(\boldsymbol{z} \mid \boldsymbol{y}, \mathbf{K})\|_{2}^{2}\tag{17}
The gradient is derived as follows:

\frac{\partial \ell}{\partial \boldsymbol{\theta}}=\frac{\partial l}{\partial \mathbf{K}} \frac{\partial \mathbf{K}}{\partial \boldsymbol{\theta}}+\frac{\partial l}{\partial \boldsymbol{y}} \frac{\partial g}{\partial \mathbf{K}} \frac{\partial \mathbf{K}}{\partial \boldsymbol{\theta}}\tag{18}

3 Object pose estimation with BPnP

Finally, the authors designed a BPnP-based pipeline for object pose estimation:

Paper & source code

Paper:https://arxiv.org/abs/1909.06043
Source code:https://github.com/BoChenYS/BPnP
Video:https://www.youtube.com/watch?v=eYmoAAsiBEE

Add a Comment

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