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
  
imports: import importlib
  import torch
  import numpy
  from collections import abc
  from einops import rearrange
  from functools import partial
  import multiprocessing
  from threading import Thread
  from queue import Queue
  from inspect import isfunction
  from PIL import Image, ImageDraw, ImageFont
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