(self, x, y)
return tf.clip_by_value((1 - ssim) / 2, 0, 1)
Computes a differentiable structured image similarity measure.
Computes a differentiable structured image similarity measure.
Computes a differentiable structured image similarity measure .
def compute_ssim_loss(self, x, y):
        """Computes a differentiable structured image similarity measure."""
        c1 = 0.01**2
        c2 = 0.03**2
        mu_x = slim.avg_pool2d(x, 3, 1, 'VALID')
        mu_y = slim.avg_pool2d(y, 3, 1, 'VALID')
        sigma_x = slim.avg_pool2d(x**2, 3, 1, 'VALID') - mu_x**2
        sigma_y = slim.avg_pool2d(y**2, 3, 1, 'VALID') - mu_y**2
        sigma_xy = slim.avg_pool2d(x * y, 3, 1, 'VALID') - mu_x * mu_y
        ssim_n = (2 * mu_x * mu_y + c1) * (2 * sigma_xy + c2)
        ssim_d = (mu_x**2 + mu_y**2 + c1) * (sigma_x + sigma_y + c2)
        ssim = ssim_n / ssim_d
        return tf.clip_by_value((1 - ssim) / 2, 0, 1)
def compute_ssim_loss ( self , x , y ) : c1 = 0.01 ** 2 c2 = 0.03 ** 2 mu_x = slim . avg_pool2d ( x , 3 , 1 , 'VALID' ) mu_y = slim . avg_pool2d ( y , 3 , 1 , 'VALID' ) sigma_x = slim . avg_pool2d ( x ** 2 , 3 , 1 , 'VALID' ) - mu_x ** 2 sigma_y = slim . avg_pool2d ( y ** 2 , 3 , 1 , 'VALID' ) - mu_y ** 2 sigma_xy = slim . avg_pool2d ( x * y , 3 , 1 , 'VALID' ) - mu_x * mu_y ssim_n = ( 2 * mu_x * mu_y + c1 ) * ( 2 * sigma_xy + c2 ) ssim_d = ( mu_x ** 2 + mu_y ** 2 + c1 ) * ( sigma_x + sigma_y + c2 ) ssim = ssim_n / ssim_d return tf . clip_by_value ( ( 1 - ssim ) / 2 , 0 , 1 )