Solved by darleybarreto in post #2 
              
              
                I solved the problem with the code bellow 
def generate_grid(h, w):
    x = torch.arange(0, h)
    y = torch.arange(0, w)

    grid = torch.stack([y.expand(h,-1).t().flatten(), x.repeat(w)]).t()
    return grid.float()

evaluate_mn_dist = lambda mu, sigma, tensor: MultivariateNormal(mu, torch.diag(s…