Skip to content

Commit

Permalink
fix: model.py Merge point clouds using a differentiable method
Browse files Browse the repository at this point in the history
  • Loading branch information
AtticusZeller authored Jun 9, 2024
1 parent 4f48c56 commit c9082db
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions src/pose_estimation/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,17 @@ def forward(self, depth_last, depth_current, i: int | None):
pcd_last = project_depth(normalized_depth_last, pose_last, self.intrinsics)
pcd_current = project_depth(normalized_depth_current, pose_cur, self.intrinsics)

# projected to depth
projected_depth_last = unproject_depth(pcd_last, pose_cur, self.intrinsics)
projected_depth_current = unproject_depth(
pcd_current, pose_cur, self.intrinsics
)

# combined
combined_projected_depth = torch.min(
projected_depth_last, projected_depth_current
)
combined_projected_depth[combined_projected_depth == 0] = torch.max(
projected_depth_last, projected_depth_current
)[combined_projected_depth == 0]
# Merge point clouds using a differentiable method
# Assuming pcd_last and pcd_current are [H, W, 4]
valid_last = (pcd_last[..., 2] > 0).float() # Depth should be greater than 0
valid_current = (pcd_current[..., 2] > 0).float()
weights_last = valid_last / (valid_last + valid_current + 1e-6)
weights_current = valid_current / (valid_last + valid_current + 1e-6)

merged_pcd = weights_last.unsqueeze(-1) * pcd_last + weights_current.unsqueeze(-1) * pcd_current

# Project the merged point cloud back to depth map
combined_projected_depth = unproject_depth(merged_pcd, pose_cur, self.intrinsics)

# NOTE: Calculate depth loss
depth_loss = compute_depth_loss(
Expand Down

0 comments on commit c9082db

Please sign in to comment.