# tf_agents.utils.nest_utils.get_outer_rank

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/utils/nest_utils.py#L911-L1002) |

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 |
|---|
| - [Networks](https://www.tensorflow.org/agents/tutorials/8_networks_tutorial) |

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.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `tensors` | Nested list/tuple/dict of Tensors or SparseTensors. |
| `specs` | Nested list/tuple/dict of TensorSpecs, describing the shape of unbatched tensors. |

<br />

<br />

<br />

<br />

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

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If <br /> 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. |