# tf.keras.backend.in_train_phase

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/keras/backend/in_train_phase) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.0.0/tensorflow/python/keras/backend.py#L4248-L4286) |

Selects `x` in train phase, and `alt` otherwise.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.keras.backend.in_train_phase`](https://www.tensorflow.org/api_docs/python/tf/keras/backend/in_train_phase)

<br />

    tf.keras.backend.in_train_phase(
        x, alt, training=None
    )

Note that `alt` should have the *same shape* as `x`.

<br />

<br />

<br />

| ## Arguments ||
|---|---|
| `x` | What to return in train phase (tensor or callable that returns a tensor). |
| `alt` | What to return otherwise (tensor or callable that returns a tensor). |
| `training` | Optional scalar tensor (or Python boolean, or Python integer) specifying the learning phase. |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| Either `x` or `alt` based on the `training` flag. the `training` flag defaults to `K.learning_phase()`. ||

<br />