# tf_agents.networks.utils.BatchSquash

<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/networks/utils.py#L49-L124) |

Facilitates flattening and unflattening batch dims of a tensor.

    tf_agents.networks.utils.BatchSquash(
        batch_dims
    )

### Used in the notebooks

| Used in the tutorials |
|---|
| - [Networks](https://www.tensorflow.org/agents/tutorials/8_networks_tutorial) |

Exposes a pair of matched faltten and unflatten methods. After flattening only
1 batch dimension will be left. This facilitates evaluating networks that
expect inputs to have only 1 batch dimension.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `batch_dims` | Number of batch dimensions the flatten/unflatten ops should handle. |

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | if batch dims is negative. |

<br />

## Methods

### `flatten`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/networks/utils.py#L72-L106)

    flatten(
        tensor
    )

Flattens and caches the tensor's batch_dims.

### `unflatten`

[View source](https://github.com/tensorflow/agents/blob/v0.19.0/tf_agents/networks/utils.py#L108-L124)

    unflatten(
        tensor
    )

Unflattens the tensor's batch_dims using the cached shape.