# tf.estimator.EstimatorSpec

<br />

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

Ops and objects returned from a `model_fn` and passed to an `Estimator`.

#### View aliases


**Compat aliases for migration**

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

[`tf.compat.v1.estimator.EstimatorSpec`](https://www.tensorflow.org/api_docs/python/tf/estimator/EstimatorSpec), \`tf.compat.v2.estimator.EstimatorSpec\`

<br />

    tf.estimator.EstimatorSpec(
        mode, predictions=None, loss=None, train_op=None, eval_metric_ops=None,
        export_outputs=None, training_chief_hooks=None, training_hooks=None,
        scaffold=None, evaluation_hooks=None, prediction_hooks=None
    )

`EstimatorSpec` fully defines the model to be run by an `Estimator`.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `mode` | A `ModeKeys`. Specifies if this is training, evaluation or prediction. |
| `predictions` | Predictions `Tensor` or dict of `Tensor`. |
| `loss` | Training loss `Tensor`. Must be either scalar, or with shape `[1]`. |
| `train_op` | Op for the training step. |
| `eval_metric_ops` | Dict of metric results keyed by name. The values of the dict can be one of the following: (1) instance of `Metric` class. (2) Results of calling a metric function, namely a `(metric_tensor, update_op)` tuple. `metric_tensor` should be evaluated without any impact on state (typically is a pure computation results based on variables.). For example, it should not trigger the `update_op` or requires any input fetching. |
| `export_outputs` | Describes the output signatures to be exported to `SavedModel` and used during serving. A dict `{name: output}` where: <br /> - name: An arbitrary name for this output. - output: an `ExportOutput` object such as `ClassificationOutput`, `RegressionOutput`, or `PredictOutput`. Single-headed models only need to specify one entry in this dictionary. Multi-headed models should specify one entry for each head, one of which must be named using [`tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/saved_model/signature_constants#DEFAULT_SERVING_SIGNATURE_DEF_KEY). If no entry is provided, a default `PredictOutput` mapping to `predictions` will be created. |
| `training_chief_hooks` | Iterable of [`tf.train.SessionRunHook`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/SessionRunHook) objects to run on the chief worker during training. |
| `training_hooks` | Iterable of [`tf.train.SessionRunHook`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/SessionRunHook) objects to run on all workers during training. |
| `scaffold` | A [`tf.train.Scaffold`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/Scaffold) object that can be used to set initialization, saver, and more to be used in training. |
| `evaluation_hooks` | Iterable of [`tf.train.SessionRunHook`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/SessionRunHook) objects to run during evaluation. |
| `prediction_hooks` | Iterable of [`tf.train.SessionRunHook`](https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/train/SessionRunHook) objects to run during predictions. |

<br />

<br />

<br />

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

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `mode` | <br /> <br /> |
| `predictions` | <br /> <br /> |
| `loss` | <br /> <br /> |
| `train_op` | <br /> <br /> |
| `eval_metric_ops` | <br /> <br /> |
| `export_outputs` | <br /> <br /> |
| `training_chief_hooks` | <br /> <br /> |
| `training_hooks` | <br /> <br /> |
| `scaffold` | <br /> <br /> |
| `evaluation_hooks` | <br /> <br /> |
| `prediction_hooks` | <br /> <br /> |

<br />