code: def save_logs(logs, path, n_saved=0, key="sample", np_path=None):
      for k in logs:
          if k == key:
              batch = logs[key]
              if np_path is None:
                  for x in batch:
                      img = custom_to_pil(x)
                      imgpath = os.path.join(
                          path, f"{key}_{n_saved:06}.png"
                      )
                      img.save(imgpath)
                      n_saved += 1
              else:
                  npbatch = custom_to_np(batch)
                  shape_str = "x".join([str(x) for x in npbatch.shape])
                  nppath = os.path.join(
                      np_path, f"{n_saved}-{shape_str}-samples.npz"
                  )
                  np.savez(nppath, npbatch)
                  n_saved += npbatch.shape[0]
      return n_saved
  
imports: import argparse
  import datetime
  import glob
  import os
  import sys
  import time
  import numpy
  import torch
  import yaml
  from ldm.models.diffusion.ddim import DDIMSampler
  from ldm.util import instantiate_from_config
  from omegaconf import OmegaConf
  from PIL import Image
  from tqdm import trange
label_desc: Use image node_id 8 for calling a global function with example usage: save_logs(logs, path, n_saved, key, np_path) and returns: n_saved