code: def numpy_to_torch(
      data: List[np.ndarray],
      resize: int = None,
      crop: int = None,
      mean: List = None,
      std: List = None,
  ) -> Dataset:
      """Convert data from list of numpy arrays [input, target] to torch datasets."""
      # Unpack arrays.
      images, labels = data
  
      # Rescale images to 0-255 and convert to uint8.
      # TODO: Right now this is done for each dataset individually, which is probably
      #   not a big deal, because all datasets should usually contain values from the
      #   complete range of values. Ideally though, this should probably be done based
      #   on the values of the train dataset.
      images = (images - np.min(images)) / np.ptp(images) * 255
      images = images.astype(np.uint8)
  
      # If images are grayscale, convert to RGB by duplicating channels.
      if images.shape[1] == 1:
          images = np.stack((images[:, 0],) * 3, axis=1)
  
      # Convert to channels last format (required for transforms.ToPILImage).
      images = channels_last(images)
  
      # Set up transform to convert to PIL image, do manipulations, and convert to tensor.
      # TODO: Converting to PIL and then to tensor is not super efficient, find a better
      #   method.
      transform = create_transform(
          from_numpy=True, resize=resize, crop=crop, mean=mean, std=std
      )
  
      # Convert labels to tensors.
      labels = torch.from_numpy(labels).long()
  
      # Construct dataset.
      dataset = ImageDataset(images, labels, transform=transform)
      return dataset
  
imports: import numpy
  import torch
  from torch.utils.data import Dataset
  from torchvision import datasets, transforms
  from typing import List, Union
  from pathlib import Path
  from PIL import Image
label_desc: Use image node_id 7 for calling a global function with example usage: numpy_to_torch(data, resize, crop, mean, std) and returns: dataset