def show_image_heatmap(model: nn.Module, pil_img: Image, method: str = 'transformer_attribution', transform: Any = None,
                       device: str = None):
    """
    Show image heatmap for transformer model.
    Args:
        model (`nn.Module`):
            Transformer model.
        pil_img (`Image`):
            Pil Image.
        method (`str`):
            `full`, `rollout` or `transformer_attribution`.
            Algorithm for attention vis, default is `transformer_attribution`
        transform (`Any`):
            Pytorch transforms or function, can be None by default.
        device (`str`):
            model device.

    """
    if transform is None:
        normalize = transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
        transform = transforms.Compose([
            transforms.Resize(256),
            transforms.CenterCrop(224),
            transforms.ToTensor(),
            normalize,
        ])
    if device is None:
        device = 'cuda' if torch.cuda.is_available() else 'cpu'
    model.to(device)
    img_tensor = transform(pil_img)
    if not is_matplotlib_available():
        models_log.warning('Matplotlib is not available.')
    from towhee.utils.matplotlib_utils import matplotlib
    import matplotlib.pylab as plt  # pylint: disable=import-outside-toplevel
    _, axs = plt.subplots(1, 2)
    axs[0].imshow(pil_img)
    axs[0].axis('off')
    vis_img = generate_attention(model, img_tensor, method=method, img_size=img_tensor.shape[-1], device=device)
    axs[1].imshow(vis_img)
    axs[1].axis('off')
    plt.show()
Show image heatmap for transformer model.
Args:
model (`nn.Module`):
Transformer model.
pil_img (`Image`):
Pil Image.
method (`str`):
`full`, `rollout` or `transformer_attribution`.
Algorithm for attention vis, default is `transformer_attribution`
transform (`Any`):
Pytorch transforms or function, can be None by default.
device (`str`):
model device.
towhee/models/visualization/transformer_visualization.py