class_docstr: SSimLoss.
  
  This is an implementation of structural similarity (SSIM) loss.
  This code is modified from https://github.com/Po-Hsun-Su/pytorch-ssim.
class_docstr_tok: ["SSimLoss",".","This","is","an","implementation","of","structural","similarity","(","SSIM",")","loss",".","This","code","is","modified","from","https",":","\/\/github.com\/Po-Hsun-Su\/pytorch-ssim","."]
docstr: Calculate SSIM loss.
  
  Args:
      tensor1 (torch.Tensor): Generated output.
      tensor2 (torch.Tensor): Groundtruth output.
  
  Returns:
      Tensor: Loss scalar value.
docstr_tok: ["Calculate","SSIM","loss",".","Args",":","tensor1","(","torch.Tensor",")",":","Generated","output",".","tensor2","(","torch.Tensor",")",":","Groundtruth","output",".","Returns",":","Tensor",":","Loss","scalar","value","."]
code: def ssim(self, tensor1: torch.Tensor, tensor2: torch.Tensor):
      """Calculate SSIM loss.
  
      Args:
          tensor1 (torch.Tensor): Generated output.
          tensor2 (torch.Tensor): Groundtruth output.
  
      Returns:
          Tensor: Loss scalar value.
  
      """
      window = self.window.to(tensor1.device)
      mu1 = F.conv2d(
          tensor1,
          window,
          padding=self.win_len // 2,
          groups=self.channels,
      )
      mu2 = F.conv2d(
          tensor2,
          window,
          padding=self.win_len // 2,
          groups=self.channels,
      )
      mu_corr = mu1 * mu2
  
      mu1 = mu1.pow(2)
      mu2 = mu2.pow(2)
  
      sigma1 = (
          F.conv2d(
              tensor1 * tensor1,
              window,
              padding=self.win_len // 2,
              groups=self.channels,
          )
          - mu1
      )
  
      sigma2 = (
          F.conv2d(
              tensor2 * tensor2,
              window,
              padding=self.win_len // 2,
              groups=self.channels,
          )
          - mu2
      )
  
      sigma_corr = (
          F.conv2d(
              tensor1 * tensor2,
              window,
              padding=self.win_len // 2,
              groups=self.channels,
          )
          - mu_corr
      )
  
      C1 = 0.01**2
      C2 = 0.03**2
  
      ssim_map = ((2 * mu_corr + C1) * (2 * sigma_corr + C2)) / (
          (mu1 + mu2 + C1) * (sigma1 + sigma2 + C2)
      )
      if self.average:
          return ssim_map.mean()
      return ssim_map.mean(1)
  
file_path: espnet/espnet2/tts/prodiff/loss.py
imports: from math import exp
  from typing import Tuple
  import torch
  from torch.nn import functional
  from typeguard import check_argument_types
  from espnet.nets.pytorch_backend.fastspeech.duration_predictor import DurationPredictorLoss
  from espnet.nets.pytorch_backend.nets_utils import make_non_pad_mask
label_desc: Use image node_id 3 for calling the SSimLoss obj's underlying member method code with example usage: obj.ssim(tensor1, tensor2) and returns: ssim_map, ssim_map