learnergy/math/metrics.py
def calculate_ssim(v, x):
    """Calculates the structural similarity of images.

    Args:
        v (torch.Tensor): Reconstructed images.
        x (torch.Tensor): Original images.

    Returns:
        The structural similarity between input images.

    """

    # Defines the total structural similarity
    total_ssim = 0.0

    # Detaches and sends to numpy both tensors
    v = v.cpu().detach().numpy()
    x = x.cpu().detach().numpy()

    # Gathers the width and height of original images
    width = x.shape[1]
    height = x.shape[2]

    # Iterates through every image
    for z in range(v.shape[0]):
        # Gathers the actual image
        x_indexed = x[z]

        # Reshapes the reconstructed image
        v_indexed = v[z, :].reshape((width, height))

        # Sums up to the total similarity
        total_ssim += ssim(x_indexed, v_indexed,
                           data_range=x_indexed.max()-x_indexed.min())

    return total_ssim / v.shape[0]
Calculates the structural similarity of images.

    Args:
        v (torch.Tensor): Reconstructed images.
        x (torch.Tensor): Original images.

    Returns:
        The structural similarity between input images.

    
Calculates the structural similarity of images.
Calculates the structural similarity of images .
def calculate_ssim(v, x):
    total_ssim = 0.0
    v = v.cpu().detach().numpy()
    x = x.cpu().detach().numpy()
    width = x.shape[1]
    height = x.shape[2]
    for z in range(v.shape[0]):
        x_indexed = x[z]
        v_indexed = v[z, :].reshape((width, height))
        total_ssim += ssim(x_indexed, v_indexed,
                           data_range=x_indexed.max()-x_indexed.min())
    return total_ssim / v.shape[0]
def calculate_ssim ( v , x ) : total_ssim = 0.0 v = v . cpu ( ) . detach ( ) . numpy ( ) x = x . cpu ( ) . detach ( ) . numpy ( ) width = x . shape [ 1 ] height = x . shape [ 2 ] for z in range ( v . shape [ 0 ] ) : x_indexed = x [ z ] v_indexed = v [ z , : ] . reshape ( ( width , height ) ) total_ssim += ssim ( x_indexed , v_indexed , data_range = x_indexed . max ( ) - x_indexed . min ( ) ) return total_ssim / v . shape [ 0 ]
Calculates the structural similarity of images.
Calculates the structural similarity of images .
"""Calculates the structural similarity of images.

    Args:
        v (torch.Tensor): Reconstructed images.
        x (torch.Tensor): Original images.

    Returns:
        The structural similarity between input images.

    """ # Defines the total structural similarity # Detaches and sends to numpy both tensors # Gathers the width and height of original images # Iterates through every image # Gathers the actual image # Reshapes the reconstructed image # Sums up to the total similarity
The structural similarity between input images.
The structural similarity between input images .
v
None
x
None