class_docstr: An abstract class that defines a data source.
class_docstr_tok: ["An","abstract","class","that","defines","a","data","source","."]
docstr: Wrap get_item in tf.numpy_function to allow eager execution.
  
  The only way to get Tensorflow to evaluate our simple `get_item` function
  in parallel seems to be to wrap it using tf.py_function or
  tf.numpy_function.
  
  Args:
    item_id: a single item ID encoded in a Tensor of type tf.string.
  
  Returns:
    A dictionary of tensors. See `self.get_item`.
code: def _get_item_py_function(self, item_id):
      """Wrap get_item in tf.numpy_function to allow eager execution.
  
      The only way to get Tensorflow to evaluate our simple `get_item` function
      in parallel seems to be to wrap it using tf.py_function or
      tf.numpy_function.
  
      Args:
        item_id: a single item ID encoded in a Tensor of type tf.string.
  
      Returns:
        A dictionary of tensors. See `self.get_item`.
      """
      output_signature = self._get_item_signature()
      # Unpack signature spec into types and shapes.
      output_types = nest.pack_sequence_as(
          output_signature,
          [x.dtype for x in nest.flatten(output_signature)],
      )
      output_shapes = nest.pack_sequence_as(
          output_signature,
          [x.shape for x in nest.flatten(output_signature)],
      )
      # tf.py_function and tf.numpy_function don't support a pytree of
      # TensorSpec yet so flatten them into a list.
      flattened_types = [
          tf.dtypes.as_dtype(dt) for dt in nest.flatten(output_types)
      ]
      flattened_shapes = nest.flatten(output_shapes)
  
      def _get_flat_item(i):
          values = self.get_item(i.decode())
          flattened_values = nest.flatten_up_to(output_types, values)
          # Cast types to the expected ones.
          flattened_values = [
              np.array(v, d.as_numpy_dtype)
              for v, d in zip(flattened_values, flattened_types)
          ]
          return flattened_values
  
      # Run `get_item` on the graph and get flat values.
      flat_values = tf.numpy_function(
          _get_flat_item, [item_id], flattened_types
      )
  
      # Fix the shapes of the output tensors.
      if output_shapes is not None:
          for ret_t, shape in zip(flat_values, flattened_shapes):
              ret_t.set_shape(shape)
  
      # Pack the values back into the dictionary structure.
      return nest.pack_sequence_as(output_types, flat_values)
  
imports: import abc
  import functools
  import itertools
  from typing import Any, Iterable, Optional, Sequence, Union
  from absl import logging
  from flax import jax_utils
  import jax
  import numpy
  import tensorflow
  from nerfies import camera
  from nerfies import gpath
  from nerfies import image_utils
  from nerfies import tf_camera
  from nerfies import utils
  from tensorflow.python.data.util import nest
label_desc: Use image node_id 29 for calling the DataSource obj's underlying member method code with example usage: obj._get_item_py_function(item_id) and returns: nest, flattened_values