lliuz / ARFlow

The official PyTorch implementation of the paper "Learning by Analogy: Reliable Supervision from Transformations for Unsupervised Optical Flow Estimation".
MIT License
249 stars 49 forks source link

Understanding Flow SPTransform #4

Closed YoussefFathi closed 4 years ago

YoussefFathi commented 4 years ago

I would appreciate it if you can clarify for me the following points related to specific parts of the "sp_transforms.py" file :

  1. In _transformflow() , what is the purpose of the following block of code ?

    ` # inverse transform coords x0, y0 = self.inverse_transform_coords( width=width, height=height, thetas=theta1)

    x1, y1 = self.inverse_transform_coords(
        width=width, height=height, thetas=theta2, offset_x=u, offset_y=v)
    
    # subtract and create new flow
    u = x1 - x0
    v = y1 - y0
    new_flow = torch.stack([u, v], dim=1)`
  2. Why didn't you use only the following part of the code to transform the optical flow just like the _transform_image()_ function ?

     `  # transform coords
    xq, yq = self.transform_coords(width=width, height=height, thetas=theta1)
    
    # interp2
    transformed = self._flow_interp2(new_flow, xq, yq)`
  3. What is the difference between the functionality of _inverse_transform_coords() and transform_coords()_ ?

lliuz commented 4 years ago

Since spatial transformations will lead in a change to coordinates, we should sample optical flow on the view of transformed coordinates rather than the original one.

In this code, inverse_transform_coords() transform coordinates: image and transform_coords() is its inverse operation.