# tf.contrib.framework.with_shape

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v1.15.0/tensorflow/contrib/framework/python/framework/tensor_util.py#L232-L299) |

Asserts tensor has expected shape.

    tf.contrib.framework.with_shape(
        expected_shape, tensor
    )

If tensor shape and expected_shape, are fully defined, assert they match.
Otherwise, add assert op that will validate the shape when tensor is
evaluated, and set shape on tensor.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `expected_shape` | Expected shape to assert, as a 1D array of ints, or tensor of same. |
| `tensor` | Tensor whose shape we're validating. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| tensor, perhaps with a dependent assert operation. ||

<br />

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | if tensor has an invalid shape. |

<br />