content: import torch
  
  COSINE_THRESHOLD = 0.99
  
  
  def cosine_similarity(gt_tensor, pred_tensor):
      gt_tensor = gt_tensor.flatten().to(torch.float32)
      pred_tensor = pred_tensor.flatten().to(torch.float32)
      if torch.sum(gt_tensor) == 0.0 or torch.sum(pred_tensor) == 0.0:
          if torch.allclose(gt_tensor, pred_tensor, atol=1e-4, rtol=1e-4, equal_nan=True):
              return 1.0
      res = torch.nn.functional.cosine_similarity(gt_tensor, pred_tensor, dim=0, eps=1e-6)
      res = res.cpu().detach().item()
  
      return res
  