code: def resize_pil(
      image_or_batch: np.ndarray,
      *,
      out_h: int,
      out_w: int,
      num_batch_dims: Optional[int] = None,
      method: str = "linear",
  ) -> np.ndarray:
      """Resizes an image or batch of images using PIL.
  
      This function handles images with or without channel dimension, but requires
      any leading batch dimensions to be specified explicitly to avoid ambiguities.
  
      Args:
        image_or_batch: Image or batch of images.
        out_h: Image height after resizing.
        out_w: Image width after resizing.
        num_batch_dims: Number of leading dimensions that are to be treated as batch
          dimensions, e.g. 0 for single images or 1 for simple batches. If None, the
          input is assumed to be a single image.
        method: String indicating the resizing method. One of "linear" or "nearest".
  
      Returns:
        Resized image or batch of images.
      """
      if num_batch_dims is None:
          num_batch_dims = 0
          if image_or_batch.ndim > 3 or (
              image_or_batch.ndim == 3
              and image_or_batch.shape[-1] not in [3, 4]
          ):
              raise ValueError(
                  "If a batch of images is supplied, num_batch_dims must "
                  "be specified."
              )
  
      if method == "linear":
          resample = Image.Resampling.BILINEAR
      elif method == "nearest":
          resample = Image.Resampling.NEAREST
      elif method == "lanczos":
          resample = Image.Resampling.LANCZOS
      else:
          raise NotImplementedError(f"Method not implemented: {method}")
  
      batch_dims = image_or_batch.shape[:num_batch_dims]
      image_dims = image_or_batch.shape[num_batch_dims:]
      batch = np.reshape(image_or_batch, (-1,) + image_dims)
  
      pil_size = [out_w, out_h]
      resized = np.stack(
          [
              np.asarray(
                  Image.fromarray(image).resize(pil_size, resample)
              )
              for image in batch
          ]
      )
  
      return np.reshape(resized, batch_dims + resized.shape[1:])
  
imports: from typing import Optional
  import jax
  import jax.numpy
  import numpy
  from PIL import Image
label_desc: Use image node_id 3 for calling a global function with example usage: resize_pil(image_or_batch) and returns: np