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(sigma)).log_prob(tensor).exp()

w, h = imgs[0].shape[1:] # imgs is the 4-D batch (B, C, W, H)
grid = generate_grid(h, w)

# for each image in the batch, get the probabilities from a gaussian distributions with
# parameters given from the VAE
maps = torch.stack([evaluate_mn_dist(mean, std, grid) for mean, std in zip(mu_final, sigma_final)])

# reshape the attention maps to get shape (Batchs, 1 , W, H)
maps = torch.unsqueeze(maps,1).view(-1,1,w,h)
# multiply the images with the maps
imgs_ = imgs*maps