code: def create_image_grid(images, grid_size=None):
      assert images.ndim == 3 or images.ndim == 4
      num, img_w, img_h = (
          images.shape[0],
          images.shape[-1],
          images.shape[-2],
      )
  
      if grid_size is not None:
          grid_w, grid_h = tuple(grid_size)
      else:
          grid_w = max(int(np.ceil(np.sqrt(num))), 1)
          grid_h = max((num - 1) // grid_w + 1, 1)
  
      grid = np.zeros(
          list(images.shape[1:-2]) + [grid_h * img_h, grid_w * img_w],
          dtype=images.dtype,
      )
      for idx in range(num):
          x = (idx % grid_w) * img_w
          y = (idx // grid_w) * img_h
          grid[..., y : y + img_h, x : x + img_w] = images[idx]
      return grid
  
file_path: insightface/reconstruction/ostec/external/stylegan2/training/misc.py
imports: import os
  import pickle
  import numpy
  import PIL.Image
  import PIL.ImageFont
  import dnnlib
label_desc: Use image node_id 5 for calling a global function with example usage: create_image_grid(images, grid_size) and returns: grid