(
surfaces: Float[Tensor, "batch frame height width 3"],
backward_flows: Float[Tensor, "batch frame-1 height width xy=2"],
backward_weights: Float[Tensor, "batch frame-1 height width"],
indices: Int64[Tensor, " pixel_index"],
)
| 211 | |
| 212 | |
| 213 | def align_surfaces( |
| 214 | surfaces: Float[Tensor, "batch frame height width 3"], |
| 215 | backward_flows: Float[Tensor, "batch frame-1 height width xy=2"], |
| 216 | backward_weights: Float[Tensor, "batch frame-1 height width"], |
| 217 | indices: Int64[Tensor, " pixel_index"], |
| 218 | ) -> Float[Tensor, "batch frame 4 4"]: |
| 219 | b, f, h, w, _ = surfaces.shape |
| 220 | |
| 221 | # Convert the depth maps into camera-space 3D surfaces (b, f, h, w, xyz). |
| 222 | xy, _ = sample_image_grid((h, w), device=surfaces.device) |
| 223 | |
| 224 | # Subsample the surfaces to select points for Procrustes alignment. Select the later |
| 225 | # points from the surfaces using the provided indices. |
| 226 | xyz_later = rearrange(later(surfaces), "b f h w xyz -> b f (h w) xyz") |
| 227 | xyz_later = xyz_later[:, :, indices] |
| 228 | |
| 229 | # Flow the grid of XY locations backwards, then select from the flowed XY locations |
| 230 | # using the provided indices. |
| 231 | xy_earlier = rearrange(xy + backward_flows, "b f h w xy -> b f (h w) xy") |
| 232 | xy_earlier = xy_earlier[:, :, indices] |
| 233 | |
| 234 | # Use the earlier XY locations to select from the earlier 3D surfaces. |
| 235 | xyz_earlier = F.grid_sample( |
| 236 | rearrange(earlier(surfaces), "b f h w xyz -> (b f) xyz h w"), |
| 237 | rearrange(xy_earlier * 2 - 1, "b f p xy -> (b f) p () xy"), |
| 238 | mode="bilinear", |
| 239 | padding_mode="border", |
| 240 | align_corners=False, |
| 241 | ) |
| 242 | xyz_earlier = rearrange(xyz_earlier, "(b f) xyz p () -> b f p xyz", b=b, f=f - 1) |
| 243 | |
| 244 | # Estimate poses via Procrustes alignment. |
| 245 | inverse_relative_transformations = align_rigid( |
| 246 | xyz_later, |
| 247 | xyz_earlier, |
| 248 | rearrange(backward_weights, "b f h w -> b f (h w)")[..., indices], |
| 249 | ) |
| 250 | extrinsics = get_extrinsics(inverse_relative_transformations) |
| 251 | |
| 252 | return extrinsics |
| 253 | |
| 254 | |
| 255 | def compute_track_flow( |
no test coverage detected