# tf.estimator.TrainSpec

<br />

|---|---|
| [![](https://www.tensorflow.org/images/tf_logo_32px.png) TensorFlow 1 version](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/estimator/TrainSpec) | [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/estimator/tree/master/tensorflow_estimator/python/estimator/training.py) |

Configuration for the "train" part for the `train_and_evaluate` call.

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.estimator.TrainSpec`](https://www.tensorflow.org/api_docs/python/tf/estimator/TrainSpec)

<br />

    tf.estimator.TrainSpec(
        input_fn, max_steps=None, hooks=None
    )

`TrainSpec` determines the input data for the training, as well as the
duration. Optional hooks run at various stages of training.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `input_fn` | A function that provides input data for training as minibatches. See [Premade Estimators](https://tensorflow.org/guide/premade_estimators#create_input_functions) for more information. The function should construct and return one of the following: <br /> - A 'tf.data.Dataset' object: Outputs of `Dataset` object must be a tuple (features, labels) with same constraints as below. - A tuple (features, labels): Where features is a `Tensor` or a dictionary of string feature name to `Tensor` and labels is a `Tensor` or a dictionary of string label name to `Tensor`. |
| `max_steps` | Int. Positive number of total steps for which to train model. If `None`, train forever. The training `input_fn` is not expected to generate `OutOfRangeError` or `StopIteration` exceptions. See the `train_and_evaluate` stop condition section for details. |
| `hooks` | Iterable of `tf.train.SessionRunHook` objects to run on all workers (including chief) during training. |

<br />

<br />

<br />

| ## Raises ||
|---|---|
| `ValueError` | If any of the input arguments is invalid. |
| `TypeError` | If any of the arguments is not of the expected type. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `input_fn` | <br /> <br /> |
| `max_steps` | <br /> <br /> |
| `hooks` | <br /> <br /> |

<br />