code: def dali_converter(inputs, device=None):
      """Convert DALI arrays to Numpy/CuPy arrays"""
  
      outputs = []
      for i in range(len(inputs)):
          x = inputs[i].as_tensor()
          if isinstance(x, dali.backend_impl.TensorCPU):
              x = np.array(x)
              if x.ndim == 2 and x.shape[1] == 1:
                  x = x.squeeze(axis=1)
              if device is not None and device >= 0:
                  x = cuda.to_gpu(x, device)
          elif isinstance(x, dali.backend_impl.TensorGPU):
              x_cupy = cuda.cupy.empty(shape=x.shape(), dtype=x.dtype())
              # Synchronization is necessary here to avoid data corruption
              # because DALI and CuPy will use different CUDA streams.
              cuda.cupy.cuda.runtime.deviceSynchronize()
              # copy data from DALI array to CuPy array
              x.copy_to_external(ctypes.c_void_p(x_cupy.data.ptr))
              cuda.cupy.cuda.runtime.deviceSynchronize()
              x = x_cupy.astype(chainer.get_dtype())
              if device is not None and device < 0:
                  x = cuda.to_cpu(x)
          else:
              raise ValueError("Unexpected object")
          outputs.append(x)
      return tuple(outputs)
  
file_path: chainer/examples/imagenet/dali_util.py
imports: import numpy
  import chainer
  from chainer.backends import cuda
  import ctypes
label_desc: Use image node_id 2 for calling a global function with example usage: dali_converter(inputs, device) and returns: tuple