import torch


def rgb_images_of_weights(weights):
    """
    Convert weights into a bunch of rgb images. 1 maps to red, -1 maps to blue, 0 to green. Others values are mixed.
    
    Args:
        weights: torch.Tensor with the shape of [n, width, height]
        
    Returns:
        images: torch.Tensor with shape of [n, 3, width, height]
    """
    weights = torch.unsqueeze(weights, 1)
    r = torch.clamp(weights, min=0.0)
    b = torch.clamp(-weights, min=0.0)
    g = 1 - r - b
    img = torch.cat([(r - 0.5) * 2, (g - 0.5) * 2, (b - 0.5) * 2], 1)
    return img