v9.1.1
Menu

Gradient Descent Update

mediumPROBundle AdjustmentOptimizationCV: Image Alignment and Stitching

Implement a gradient descent update step for camera parameters in the context of Bundle Adjustment, a crucial process in Image Alignment and Stitching. You are given the current camera parameters and their gradient, and need to perform one update step to minimize a cost function.

The goal of gradient descent is to iteratively update parameters to minimize the cost function, which measures the difference between observed and predicted values. The learning rate controls the step size of each update. The gradient of the cost function points in the direction of the steepest ascent, so subtracting it from the current parameters moves them downhill toward the minimum.

Here are the steps to update the parameters:

  1. Compute the gradient of the cost function with respect to the current parameters.
  2. Multiply the gradient by the learning rate.
  3. Subtract the result from the current parameters to obtain the updated parameters.
θnew=θold−η⋅∇C\theta_{new} = \theta_{old} - \eta \cdot \nabla C

This technique is widely used in computer vision applications, such as image stitching and 3D reconstruction.

Example

Input
translation = [1, 1, 1]
gradient = [0.1, 0.2, 0.3]
learning_rate = 0.1
Output
[0.99, 0.98, 0.97]
Reasoning
  • Inputs: translation is the camera position θ=(tx,ty,tz)=(1,1,1)\theta = (t_x, t_y, t_z) = (1, 1, 1); gradient is ∇C=(0.1,0.2,0.3)\nabla C = (0.1, 0.2, 0.3), how fast the cost rises along each axis; learning_rate is the step size η=0.1\eta = 0.1.
  • Scale the gradient: η⋅∇C=(0.1×0.1, 0.1×0.2, 0.1×0.3)=(0.01,0.02,0.03)\eta \cdot \nabla C = (0.1 \times 0.1,\ 0.1 \times 0.2,\ 0.1 \times 0.3) = (0.01, 0.02, 0.03).
  • Step against it: each component moves independently, θnew=θold−η∇C\theta_{new} = \theta_{old} - \eta \nabla C, giving 1−0.01=0.991 - 0.01 = 0.99, 1−0.02=0.981 - 0.02 = 0.98 and 1−0.03=0.971 - 0.03 = 0.97.
  • Output: a list of three numbers in the same (tx,ty,tz)(t_x, t_y, t_z) order, rounded to 4 decimal places: [0.99, 0.98, 0.97].
  • Notice: the axis with the steepest cost (tzt_z, gradient 0.30.3) moves the most. Every coordinate decreases because every gradient entry is positive; a zero gradient would leave the translation unchanged, and a larger η\eta would take a bigger step.

Constraints

  • translation: current [tx, ty, tz]
  • gradient: cost gradient [∂C/∂tx, ∂C/∂ty, ∂C/∂tz]
  • learning_rate: step size η
  • Return updated translation
  • Round to 4 decimal places

Learn this in

More from CV: Image Alignment and Stitching

PRO

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test results

Sign in to run your code against the test cases.