code: def create_gradient_log_loss(log_prediction_d, mask, log_gt):
      # compute log difference
      log_d_diff = log_prediction_d - log_gt
      log_d_diff = torch.mul(log_d_diff, mask)
  
      # compute vertical gradient
      v_gradient = torch.abs(
          log_d_diff[:, :, 2:, :] - log_d_diff[:, :, :-2, :]
      )
      v_mask = torch.mul(mask[:, :, 2:, :], mask[:, :, :-2, :])
      v_gradient = torch.mul(v_gradient, v_mask)
  
      # compute horizontal gradient
      h_gradient = torch.abs(
          log_d_diff[:, :, :, 2:] - log_d_diff[:, :, :, :-2]
      )
      h_mask = torch.mul(mask[:, :, :, 2:], mask[:, :, :, :-2])
      h_gradient = torch.mul(h_gradient, h_mask)
  
      # sum up gradients
      grad_loss = torch.sum(h_gradient, dim=[1, 2, 3]) + torch.sum(
          v_gradient, dim=[1, 2, 3]
      )
      num_valid_pixels = torch.sum(mask, dim=[1, 2, 3])
      grad_loss = div_by_mask_sum(grad_loss, num_valid_pixels)
  
      return grad_loss
  
file_path: ARKitScenes/depth_upsampling/losses/gradient_loss.py
imports: import torch
  import dataset_keys
label_desc: Use image node_id 2 for calling a global function with example usage: create_gradient_log_loss(log_prediction_d, mask, log_gt) and returns: grad_loss