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


View source on GitHub

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

    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.


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


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


  • 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.