Missed TensorFlow Dev Summit? Check out the video playlist. Watch recordings

tf_agents.utils.nest_utils.get_outer_rank

View source on GitHub

Compares tensors to specs to determine the number of batch dimensions.

tf_agents.utils.nest_utils.get_outer_rank(
    tensors, specs
)

Used in the notebooks

Used in the tutorials

For each tensor, it checks the dimensions with respect to specs and returns the number of batch dimensions if all nested tensors and specs agree with each other.

Args:

  • tensors: Nested list/tuple/dict of Tensors or SparseTensors.
  • specs: Nested list/tuple/dict of TensorSpecs, describing the shape of unbatched tensors.

Returns:

The number of outer dimensions for all Tensors (zero if all are unbatched or empty).

Raises:

  • ValueError: If
    1. Any of the tensors or specs have shapes with ndims == None, or
    2. The shape of Tensors are not compatible with specs, or
    3. A mix of batched and unbatched tensors are provided.
    4. The tensors are batched but have an incorrect number of outer dims.