code: def log_txt_as_img(wh, xc, size=10):
      # wh a tuple of (width, height)
      # xc a list of captions to plot
      b = len(xc)
      txts = list()
      for bi in range(b):
          txt = Image.new("RGB", wh, color="white")
          draw = ImageDraw.Draw(txt)
          font = ImageFont.truetype("data/DejaVuSans.ttf", size=size)
          nc = int(40 * (wh[0] / 256))
          lines = "\n".join(
              xc[bi][start : start + nc]
              for start in range(0, len(xc[bi]), nc)
          )
  
          try:
              draw.text((0, 0), lines, fill="black", font=font)
          except UnicodeEncodeError:
              print("Cant encode string for logging. Skipping.")
  
          txt = np.array(txt).transpose(2, 0, 1) / 127.5 - 1.0
          txts.append(txt)
      txts = np.stack(txts)
      txts = torch.tensor(txts)
      return txts
  
file_path: ColossalAI/examples/images/diffusion/ldm/util.py
imports: import importlib
  from inspect import isfunction
  import numpy
  import torch
  from PIL import Image, ImageDraw, ImageFont
  from torch import optim
label_desc: Use image node_id 1 for calling a global function with example usage: log_txt_as_img(wh, xc, size) and returns: txts