code: 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()
  
file_path: towhee/towhee/models/visualization/transformer_visualization.py
imports: from typing import Any
  from torch import nn
  import torch
  from torchvision import transforms
  import numpy
  from towhee.utils.pil_utils import PILImage
  from towhee.utils.cv2_utils import cv2
  from towhee.trainer.utils.file_utils import is_matplotlib_available
  from towhee.utils.log import models_log
label_desc: Use image node_id 4 for calling a global function with example usage: show_image_heatmap(model, pil_img, method, transform, device) without return types