code: def makepmask(
      self, mask, h, w, th, step
  ):  # make masks from attention cache return [for preview, for attention, for Latent]
      th = th - step * 0.005
      if 0.05 >= th:
          th = 0.05
      mask = torch.mean(mask, dim=0)
      mask = mask / mask.max().item()
      mask = torch.where(mask > th, 1, 0)
      mask = mask.float()
      mask = mask.view(1, *self.attnmaps_sizes[0])
      img = FF.to_pil_image(mask)
      img = img.resize((w, h))
      mask = FF.resize(
          mask,
          (h, w),
          interpolation=FF.InterpolationMode.NEAREST,
          antialias=None,
      )
      lmask = mask
      mask = mask.reshape(h * w)
      mask = torch.where(mask > 0.1, 1, 0)
      return img, mask, lmask
  
imports: import math
  from typing import Dict, Optional
  import torch
  import torchvision.transforms.functional
  from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer
  from diffusers import StableDiffusionPipeline
  from diffusers.models import AutoencoderKL, UNet2DConditionModel
  from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker
  from diffusers.schedulers import KarrasDiffusionSchedulers
  from diffusers.utils import USE_PEFT_BACKEND
label_desc: Use image node_id 8 for calling a global function with example usage: makepmask(mask, h, w, th, step) and returns: img,  mask,  lmask