Skip to content

SSIM and kornia.geometry.depth.warp_frame_depth #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions undeepvo/criterion/disparity_consistency_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def get_disparities(self, left_depth_map, right_depth_map):
return left_disparity, right_disparity

def generate_disparity_maps(self, left_disparity, right_disparity, left_current_depth, right_current_depth):
generated_right_disparity = kornia.warp_frame_depth(image_src=left_disparity,
generated_right_disparity = kornia.geometry.depth.warp_frame_depth(image_src=left_disparity,
depth_dst=right_current_depth,
src_trans_dst=self.transform_from_left_to_right,
camera_matrix=self.left_camera_matrix)

generated_left_disparity = kornia.warp_frame_depth(image_src=right_disparity,
generated_left_disparity = kornia.geometry.depth.warp_frame_depth(image_src=right_disparity,
depth_dst=left_current_depth,
src_trans_dst=torch.inverse(
self.transform_from_left_to_right),
Expand Down
4 changes: 2 additions & 2 deletions undeepvo/criterion/registration_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ def __init__(self, registration_lambda, camera_matrix):
self.camera_matrix = camera_matrix

def generate_next_image(self, current_image, next_depth, transformation_from_next_to_current):
generated_next_image = kornia.warp_frame_depth(current_image,
generated_next_image = kornia.geometry.depth.warp_frame_depth(current_image,
next_depth,
transformation_from_next_to_current,
self.camera_matrix)
return generated_next_image

def generate_current_image(self, next_image, current_depth, transformation_from_current_to_next):
generated_current_image = kornia.warp_frame_depth(next_image,
generated_current_image = kornia.geometry.depth.warp_frame_depth(next_image,
current_depth,
transformation_from_current_to_next,
self.camera_matrix)
Expand Down
6 changes: 3 additions & 3 deletions undeepvo/criterion/spatial_photometric_consistency_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ def __init__(self, lambda_s, left_camera_matrix, right_camera_matrix, transform_
self.transform_from_left_to_right = transform_from_left_to_right

self.l1_loss = torch.nn.L1Loss()
self.SSIM_loss = kornia.losses.SSIM(window_size=self.window_size, reduction=self.reduction,
self.SSIM_loss = kornia.losses.SSIMLoss(window_size=self.window_size, reduction=self.reduction,
max_val=self.max_val)

def forward(self, left_current_img, right_current_img, left_current_depth, right_current_depth):
generated_right_img = kornia.warp_frame_depth(image_src=left_current_img,
generated_right_img = kornia.geometry.depth.warp_frame_depth(image_src=left_current_img,
depth_dst=right_current_depth,
src_trans_dst=torch.inverse(self.transform_from_left_to_right),
camera_matrix=self.left_camera_matrix)

generated_left_img = kornia.warp_frame_depth(image_src=right_current_img,
generated_left_img = kornia.geometry.depth.warp_frame_depth(image_src=right_current_img,
depth_dst=left_current_depth,
src_trans_dst=self.transform_from_left_to_right,
camera_matrix=self.right_camera_matrix)
Expand Down
6 changes: 3 additions & 3 deletions undeepvo/criterion/temporal_photometric_consistency_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ def __init__(self, camera_matrix, right_camera_matrix,
super().__init__()
self.camera_matrix = camera_matrix
self.lambda_s = lambda_s
self.ssim_loss = kornia.losses.SSIM(window_size=window_size, reduction=reduction, max_val=max_val)
self.ssim_loss = kornia.losses.SSIMLoss(window_size=window_size, reduction=reduction, max_val=max_val)
self.l1_loss = torch.nn.L1Loss()

def calculate_loss(self, image1, image2):
loss = self.lambda_s * self.ssim_loss(image1, image2) + (1 - self.lambda_s) * self.l1_loss(image1, image2)
return loss

def generate_next_image(self, current_image, next_depth, transformation_from_next_to_current):
generated_next_image = kornia.warp_frame_depth(current_image,
generated_next_image = kornia.geometry.depth.warp_frame_depth(current_image,
next_depth,
transformation_from_next_to_current,
self.camera_matrix)
return generated_next_image

def generate_current_image(self, next_image, current_depth, transformation_from_current_to_next):
generated_current_image = kornia.warp_frame_depth(next_image,
generated_current_image = kornia.geometry.depth.warp_frame_depth(next_image,
current_depth,
transformation_from_current_to_next,
self.camera_matrix)
Expand Down
4 changes: 2 additions & 2 deletions undeepvo/problems/unsupervised_depth_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ def _get_synthesized_image(self):
right_current_image = data_point["right_current_image"][None].to(self._device)
cameras_calibration = self._dataset_manager.get_cameras_calibration(device=self._device)
with torch.no_grad():
generated_left_image = kornia.warp_frame_depth(right_current_image,
generated_left_image = kornia.geometry.depth.warp_frame_depth(right_current_image,
left_current_depth,
cameras_calibration.transform_from_left_to_right,
cameras_calibration.left_camera_matrix)
generated_right_image = kornia.warp_frame_depth(left_current_image,
generated_right_image = kornia.geometry.depth.warp_frame_depth(left_current_image,
right_current_depth,
torch.inverse(
cameras_calibration.transform_from_left_to_right),
Expand Down