def forward(self, input, target, max_val=None):
     max_val = self.max_val if max_val is None else max_val
     input = input.unsqueeze(1)
     print (input.max())
     target = target.unsqueeze(1)
     return 1- ssim_loss(input, target, max_val=max_val, filter_size=self.filter_size, k1=self.k1, k2=self.k2,
                          sigma=self.sigma, reduction=self.reduction)
Example #2
0
 def forward(self, input, target, max_val=None):
     max_val = self.max_val if max_val is None else max_val
     return 1 - ssim_loss(input,
                          target,
                          max_val=max_val,
                          filter_size=self.filter_size,
                          k1=self.k1,
                          k2=self.k2,
                          sigma=self.sigma,
                          reduction=self.reduction)
Example #3
0
    def _get_slice_metrics(img_recons, img_targets):

        img_recons = img_recons.detach()  # Just in case.
        img_targets = img_targets.detach()

        max_range = img_targets.max() - img_targets.min()
        slice_ssim = ssim_loss(img_recons, img_targets, max_val=max_range)
        slice_psnr = psnr(img_recons, img_targets, data_range=max_range)
        slice_nmse = nmse(img_recons, img_targets)

        return {'slice_ssim': slice_ssim, 'slice_nmse': slice_nmse, 'slice_psnr': slice_psnr}
Example #4
0
    def forward(self, input, target, max_val=None):
        max_val = self.max_val if max_val is None else max_val

        cssim = 1 - ssim_loss(input,
                              target,
                              max_val=max_val,
                              filter_size=self.filter_size,
                              k1=self.k1,
                              k2=self.k2,
                              sigma=self.sigma,
                              reduction=self.reduction)

        l1_loss = F.l1_loss(input, target, reduction=self.reduction)

        return cssim + self.l1_weight * l1_loss