code: def recursive_unpack(batch):
      """
      Takes a batch of samples, e.g.
  
        batch = {'input': tensor([256, 3, 224, 224]), 'target': tensor([256])}
  
      and unpacks them into a list of single samples, e.g.
  
        [{'input': tensor([1, 3, 224, 224]), 'target': tensor([1])} ... ]
      """
      new_list = []
      if isinstance(batch, dict):
          unpacked_dict = {}
          batchsize_per_replica = -1
          for key, val in batch.items():
              unpacked_dict[key] = recursive_unpack(val)
              batchsize_per_replica = (
                  len(unpacked_dict[key])
                  if not torch.is_tensor(unpacked_dict[key])
                  else 1
              )
  
          for idx in range(batchsize_per_replica):
              sample = {}
              for key, val in unpacked_dict.items():
                  sample[key] = val[idx]
  
              new_list.append(sample)
          return new_list
  
      elif isinstance(batch, (list, tuple)):
          unpacked_list = []
          if isinstance(batch, tuple):
              batch = list(batch)
  
          for val in batch:
              unpacked_list.append(recursive_unpack(val))
              batchsize_per_replica = (
                  len(unpacked_list[0])
                  if not torch.is_tensor(unpacked_list[0])
                  else 1
              )
  
          for idx in range(batchsize_per_replica):
              sample = []
              for val in unpacked_list:
                  sample.append(val[idx])
  
              if isinstance(batch, tuple):
                  sample = tuple(sample)
              new_list.append(sample)
          return new_list
  
      elif torch.is_tensor(batch):
          for i in range(batch.size()[0]):
              new_list.append(batch[i])
          return new_list
  
      raise TypeError(
          "Unexpected type %s passed to unpack" % type(batch)
      )
  
imports: import os
  import unittest
  from functools import wraps
  import torch
  from classy_vision.hooks import ClassyHook
  from classy_vision.tasks import ClassyTask
  from classy_vision.trainer import ClassyTrainer
label_desc: Use image node_id 7 for calling a global function with example usage: recursive_unpack(batch) and returns: new_list, new_list, new_list