import torch


def get_nmse(x_hat, x):
    """
    Calculate ||x_hat - x|| / ||x||
    """
    sse = torch.sum((x_hat - x)**2, dim=[1,2,3]) #shape [N] - sse per image
    denom = torch.sum(x**2, dim=[1,2,3]) #shape [N] - squared l2 norm per ground truth image

    nmse_val = sse / denom

    return nmse_val.cpu().numpy().flatten()